Skip to content

Commit

Permalink
test: more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
domoritz committed Dec 22, 2020
1 parent c918617 commit 8cd4641
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ export function stack(
}

// warn when stacking non-linear
if (stackedFieldDef.scale && stackedFieldDef.scale.type && stackedFieldDef.scale.type !== ScaleType.LINEAR) {
if (stackedFieldDef?.scale?.type && stackedFieldDef?.scale?.type !== ScaleType.LINEAR) {
if (opt.disallowNonLinearStack) {
return null;
} else {
Expand Down
19 changes: 17 additions & 2 deletions test/stack.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe('stack', () => {
}
};
const stackProps = stack(spec.mark, spec.encoding, undefined);
expect(stackProps.fieldChannel).toBe('x');
expect(stackProps.fieldChannel).toBe(X);
}
});

Expand All @@ -58,6 +58,21 @@ describe('stack', () => {
}
});

it('should stack default stack marks', () => {
for (const mark of STACK_BY_DEFAULT_MARKS) {
const spec: TopLevel<NormalizedUnitSpec> = {
data: {url: 'data/barley.json'},
mark: mark,
encoding: {
x: {field: 'yield', type: 'quantitative'},
y: {field: 'variety', type: 'nominal'}
}
};
const stackProps = stack(spec.mark, spec.encoding, undefined);
expect(stackProps.fieldChannel).toBe(X);
}
});

it('should prioritize axis with stack', () => {
for (const mark of STACKABLE_NON_POLAR_MARKS) {
const spec: TopLevel<NormalizedUnitSpec> = {
Expand All @@ -70,7 +85,7 @@ describe('stack', () => {
}
};
const stackProps = stack(spec.mark, spec.encoding, undefined);
expect(stackProps.fieldChannel).toBe('x');
expect(stackProps.fieldChannel).toBe(X);
}
});

Expand Down

0 comments on commit 8cd4641

Please sign in to comment.