|
1 | 1 | import schemaUtils from '../src/index';
|
2 | 2 |
|
3 | 3 | import schema from './fixtures/schema.json';
|
| 4 | +import schemaTitle from './fixtures/schema-title.json'; |
| 5 | +import schemaTitleBrone from './fixtures/schema-title-broken.json'; |
4 | 6 |
|
5 | 7 | describe('api', () => {
|
6 | 8 | it('should export validate and ValidateError', () => {
|
@@ -32,4 +34,72 @@ describe('api', () => {
|
32 | 34 |
|
33 | 35 | schemaUtils(schema, options);
|
34 | 36 | });
|
| 37 | + |
| 38 | + it('should get configuration from schema', () => { |
| 39 | + try { |
| 40 | + schemaUtils(schemaTitle, { foo: 'bar' }); |
| 41 | + } catch (error) { |
| 42 | + if (error.name !== 'ValidationError') { |
| 43 | + throw error; |
| 44 | + } |
| 45 | + |
| 46 | + expect(error.message).toMatchSnapshot(); |
| 47 | + } |
| 48 | + }); |
| 49 | + |
| 50 | + it('should prefer configuration over "title"', () => { |
| 51 | + try { |
| 52 | + schemaUtils( |
| 53 | + schemaTitle, |
| 54 | + { foo: 'bar' }, |
| 55 | + { name: 'NAME', baseDataPath: 'BaseDataPath' } |
| 56 | + ); |
| 57 | + } catch (error) { |
| 58 | + if (error.name !== 'ValidationError') { |
| 59 | + throw error; |
| 60 | + } |
| 61 | + |
| 62 | + expect(error.message).toMatchSnapshot(); |
| 63 | + } |
| 64 | + }); |
| 65 | + |
| 66 | + it('should prefer configuration over "title" #1', () => { |
| 67 | + try { |
| 68 | + schemaUtils(schemaTitle, { foo: 'bar' }, { name: 'NAME' }); |
| 69 | + } catch (error) { |
| 70 | + if (error.name !== 'ValidationError') { |
| 71 | + throw error; |
| 72 | + } |
| 73 | + |
| 74 | + expect(error.message).toMatchSnapshot(); |
| 75 | + } |
| 76 | + }); |
| 77 | + |
| 78 | + it('should prefer configuration over "title" #2', () => { |
| 79 | + try { |
| 80 | + schemaUtils( |
| 81 | + schemaTitle, |
| 82 | + { foo: 'bar' }, |
| 83 | + { baseDataPath: 'BaseDataPath' } |
| 84 | + ); |
| 85 | + } catch (error) { |
| 86 | + if (error.name !== 'ValidationError') { |
| 87 | + throw error; |
| 88 | + } |
| 89 | + |
| 90 | + expect(error.message).toMatchSnapshot(); |
| 91 | + } |
| 92 | + }); |
| 93 | + |
| 94 | + it('should use default values when "title" is broken', () => { |
| 95 | + try { |
| 96 | + schemaUtils(schemaTitleBrone, { foo: 'bar' }); |
| 97 | + } catch (error) { |
| 98 | + if (error.name !== 'ValidationError') { |
| 99 | + throw error; |
| 100 | + } |
| 101 | + |
| 102 | + expect(error.message).toMatchSnapshot(); |
| 103 | + } |
| 104 | + }); |
35 | 105 | });
|
0 commit comments