Skip to content

Commit

Permalink
proper re-render tests
Browse files Browse the repository at this point in the history
  • Loading branch information
snewcomer committed Apr 14, 2021
1 parent c05af39 commit aa76473
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class KeywordImpl<
protected keyword: S,
type: KeywordType,
private delegate: KeywordDelegate<KeywordMatches[K], Param, Out>,
private options?: { strictOnly: boolean },
private options?: { strictOnly: boolean }
) {
let nodes = new Set<KeywordNode['type']>();
for (let nodeType of KEYWORD_NODES[type]) {
Expand All @@ -45,7 +45,10 @@ class KeywordImpl<
this.types = nodes;
}

protected match(node: KeywordCandidates[K], state: NormalizationState): node is KeywordMatches[K] {
protected match(
node: KeywordCandidates[K],
state: NormalizationState
): node is KeywordMatches[K] {
// some keywords are enabled only in strict mode. None are planned to be loose mode only
if (this.options?.strictOnly) {
if (state.isStrict === false) {
Expand Down Expand Up @@ -145,7 +148,12 @@ export function keyword<
D extends KeywordDelegate<KeywordMatches[K], unknown, Out>,
Out = unknown
>(keyword: string, type: K, delegate: D, options?: { strictOnly: boolean }): Keyword<K, Out> {
return new KeywordImpl(keyword, type, delegate as KeywordDelegate<KeywordMatch, unknown, Out>, options);
return new KeywordImpl(
keyword,
type,
delegate as KeywordDelegate<KeywordMatch, unknown, Out>,
options
);
}

export type PossibleKeyword = KeywordNode;
Expand Down
15 changes: 10 additions & 5 deletions packages/@glimmer/integration-tests/test/keywords/equality-test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RenderTest, test, jitSuite, defineComponent } from '../..';
import { RenderTest, test, jitSuite, defineComponent, trackedObj } from '../..';

class EqualTest extends RenderTest {
static suiteName = '{{eq}} keyword';
Expand Down Expand Up @@ -37,13 +37,15 @@ class EqualTest extends RenderTest {

@test
['correctly renders when values update eq']() {
let args = trackedObj({ foo: 123, bar: 456 });

const AComponent = defineComponent({}, '{{eq @foo @bar}}');
this.renderComponent(AComponent, { foo: 123, bar: 456 });
this.renderComponent(AComponent, args);

this.assertHTML('false');
this.assertStableRerender();

this.rerender({ foo: 456 });
args.foo = 456;
this.rerender();

this.assertHTML('true');
}
Expand Down Expand Up @@ -86,11 +88,14 @@ class NotEqualTest extends RenderTest {

@test
['correctly renders when values update neq']() {
let args = trackedObj({ foo: 123, bar: 456 });

const AComponent = defineComponent({}, '{{neq @foo @bar}}');
this.renderComponent(AComponent, { foo: 123, bar: 456 });
this.renderComponent(AComponent, args);

this.assertHTML('true');

args.foo = 456;
this.rerender({ foo: 456 });

this.assertHTML('false');
Expand Down

0 comments on commit aa76473

Please sign in to comment.