File size: 661 Bytes
23ac194
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
'use strict'

const { test } = require('node:test')
const validator = require('is-my-json-valid')
const build = require('..')

test('object with RexExp', (t) => {
  t.plan(3)

  const schema = {
    title: 'object with RegExp',
    type: 'object',
    properties: {
      reg: {
        type: 'string'
      }
    }
  }

  const obj = {
    reg: /"([^"]|\\")*"/
  }

  const stringify = build(schema)
  const validate = validator(schema)
  const output = stringify(obj)

  t.assert.doesNotThrow(() => JSON.parse(output))

  t.assert.equal(obj.reg.source, new RegExp(JSON.parse(output).reg).source)
  t.assert.ok(validate(JSON.parse(output)), 'valid schema')
})