mirror of
https://github.com/oliverbooth/X10D
synced 2024-11-14 04:35:41 +00:00
Oliver Booth
98cd96d5cb
The child was not being assigned a new parent, causing GetComponentsInChildrenOnly to return empty array and the subsequent line: Assert.That(components, Has.Length.EqualTo(1)); was resulting in a test fail.
32 lines
872 B
C#
32 lines
872 B
C#
#nullable enable
|
|
|
|
using System.Collections;
|
|
using NUnit.Framework;
|
|
using UnityEngine;
|
|
using UnityEngine.TestTools;
|
|
using Object = UnityEngine.Object;
|
|
|
|
namespace X10D.Unity.Tests
|
|
{
|
|
public class ComponentTests
|
|
{
|
|
[Test]
|
|
public void GetComponentsInChildrenOnly_ShouldIgnoreParent()
|
|
{
|
|
var parent = new GameObject();
|
|
var rigidbody = parent.AddComponent<Rigidbody>();
|
|
|
|
var child = new GameObject();
|
|
child.transform.SetParent(parent.transform);
|
|
child.AddComponent<Rigidbody>();
|
|
|
|
Rigidbody[] components = rigidbody.GetComponentsInChildrenOnly<Rigidbody>();
|
|
Assert.That(components, Has.Length.EqualTo(1));
|
|
Assert.That(child, Is.EqualTo(components[0].gameObject));
|
|
|
|
Object.Destroy(parent);
|
|
Object.Destroy(child);
|
|
}
|
|
}
|
|
}
|