mirror of
https://github.com/trezor/trezor-suite.git
synced 2026-03-03 05:55:03 +01:00
44 lines
1.1 KiB
TypeScript
44 lines
1.1 KiB
TypeScript
import { AssertWeak, Type } from '../src';
|
|
|
|
describe('weak-assert', () => {
|
|
it('should not throw if type is mismatched', () => {
|
|
const schema = Type.Object({
|
|
foo: Type.String(),
|
|
});
|
|
const value = {
|
|
foo: 123,
|
|
};
|
|
|
|
console.warn = jest.fn();
|
|
expect(() => AssertWeak(schema, value)).not.toThrow();
|
|
expect(console.warn).toHaveBeenCalledTimes(1);
|
|
});
|
|
|
|
it('should not throw if a property is mismatched in a union', () => {
|
|
const schema = Type.Union([
|
|
Type.Object({
|
|
foo: Type.String(),
|
|
}),
|
|
Type.Object({
|
|
bar: Type.Number(),
|
|
}),
|
|
]);
|
|
const value = {
|
|
foo: 123,
|
|
};
|
|
|
|
console.warn = jest.fn();
|
|
expect(() => AssertWeak(schema, value)).not.toThrow();
|
|
expect(console.warn).toHaveBeenCalledTimes(1);
|
|
});
|
|
|
|
it('should throw if a required field is missing', () => {
|
|
const schema = Type.Object({
|
|
foo: Type.String(),
|
|
});
|
|
const value = {};
|
|
|
|
expect(() => AssertWeak(schema, value)).toThrow();
|
|
});
|
|
});
|