Skip to content

Commit

Permalink
chore: split tests in a new objects.test.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
Ayc0 committed Aug 8, 2024
1 parent fbf58c3 commit 423b75b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 23 deletions.
23 changes: 0 additions & 23 deletions tests/is-matching.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,27 +77,4 @@ describe('isMatching', () => {
throw new Error('Expected food to match the pizza pattern!');
}
});
it('should work with symbols', () => {
const symbolA = Symbol('symbol-a');
const symbolB = Symbol('symbol-b');
const obj: { [symbolA]: { [symbolB]: 'foo' | 'bar' } } = {
[symbolA]: { [symbolB]: 'foo' },
};
if (isMatching({ [symbolA]: { [symbolB]: 'foo' } }, obj)) {
type t = Expect<Equal<typeof obj, { [symbolA]: { [symbolB]: 'foo' } }>>;
} else {
throw new Error('Expected obj to match the foo pattern!');
}
if (isMatching({ [symbolA]: { [symbolB]: 'bar' } }, obj)) {
type t = Expect<
Equal<
typeof obj,
{ [symbolA]: { [symbolB]: 'foo' } } & {
[symbolA]: { [symbolB]: 'bar' };
}
>
>;
throw new Error('Expected obj to not match the bar pattern!');
}
});
});
28 changes: 28 additions & 0 deletions tests/objects.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { isMatching, P } from '../src';
import { Equal, Expect } from '../src/types/helpers';

describe('Objects', () => {
it('should work with symbols', () => {
const symbolA = Symbol('symbol-a');
const symbolB = Symbol('symbol-b');
const obj: { [symbolA]: { [symbolB]: 'foo' | 'bar' } } = {
[symbolA]: { [symbolB]: 'foo' },
};
if (isMatching({ [symbolA]: { [symbolB]: 'foo' } }, obj)) {
type t = Expect<Equal<typeof obj, { [symbolA]: { [symbolB]: 'foo' } }>>;
} else {
throw new Error('Expected obj to match the foo pattern!');
}
if (isMatching({ [symbolA]: { [symbolB]: 'bar' } }, obj)) {
type t = Expect<
Equal<
typeof obj,
{ [symbolA]: { [symbolB]: 'foo' } } & {
[symbolA]: { [symbolB]: 'bar' };
}
>
>;
throw new Error('Expected obj to not match the bar pattern!');
}
});
});

0 comments on commit 423b75b

Please sign in to comment.