Skip to content

Commit b679130

Browse files
nicolechungynotdraw
authored andcommitted
tests: Use findAll
Co-authored-by: nicole chung <nicolechung@users.noreply.github.com>
1 parent 4dd5d32 commit b679130

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

test-app/tests/integration/components/field-test.gts

+19-14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { render } from '@ember/test-helpers';
1+
import { findAll, render } from '@ember/test-helpers';
22
import { module, test } from 'qunit';
33

44
import Field from '@crowdstrike/ember-toucan-core/components/form/field';
@@ -58,9 +58,9 @@ module('Integration | Component | Field', function (hooks) {
5858
assert.dom(hint).exists('Expected to have hint text rendered');
5959
assert.dom(hint).hasText('hint', 'Expected to have hint text "hint"');
6060

61-
let childDivs = document.querySelectorAll('[data-test-field] > div');
61+
let children = findAll('[data-test-field] > div');
6262
assert.strictEqual(
63-
childDivs.length,
63+
children.length,
6464
2,
6565
'Expect 1 div for hint, 1 div for error'
6666
);
@@ -102,22 +102,24 @@ module('Integration | Component | Field', function (hooks) {
102102
.hasText('error', 'Expected to have error text rendered');
103103
});
104104

105-
// TODO: Checkpoint: finish this
106105
test('it renders conditionally', async function (assert) {
107106
await render(<template>
108-
<Field as |field|>
109-
<field.Label>label</field.Label>
110-
<field.Hint><span data-test-hint>hint</span></field.Hint>
111-
<field.Control>
112-
<input type="text" data-test-input />
113-
</field.Control>
114-
</Field>
107+
<div data-test-field>
108+
<Field as |field|>
109+
<field.Label>label</field.Label>
110+
<field.Hint><span data-test-hint>hint</span></field.Hint>
111+
<field.Control>
112+
<input type="text" data-test-input />
113+
</field.Control>
114+
</Field>
115+
</div>
115116
</template>);
116117

117118
const label = 'label';
118119
const hint = '[data-test-hint]';
119120
const error = '[data-test-error]';
120121
const control = '[data-test-input]';
122+
const children = findAll('[data-test-field] > div');
121123

122124
assert.dom(label).exists('Expected to have label block rendered');
123125
assert.dom(label).hasText('label', 'Expected to have label text "label"');
@@ -130,9 +132,12 @@ module('Integration | Component | Field', function (hooks) {
130132
assert
131133
.dom('svg')
132134
.doesNotExist('Error block does not exist (no error icon shown)');
133-
assert
134-
.dom(error)
135-
.hasText('error', 'Expected to have error text rendered');
135+
136+
assert.strictEqual(
137+
children.length,
138+
1,
139+
'Form only has div which is the hint'
140+
);
136141
});
137142
});
138143
});

0 commit comments

Comments
 (0)