-
-
Notifications
You must be signed in to change notification settings - Fork 208
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix "isLong is not defined" error (#73)
* extract checks for isLong * install proxyquire as dev dependency * add integer tests without long * fix rendering of additional non long integers
- Loading branch information
1 parent
8124cfe
commit ebd32f8
Showing
3 changed files
with
122 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
'use strict' | ||
|
||
const test = require('tap').test | ||
const validator = require('is-my-json-valid') | ||
const proxyquire = require('proxyquire') | ||
const build = proxyquire('..', { long: null }) | ||
|
||
test(`render an integer as JSON`, (t) => { | ||
t.plan(2) | ||
|
||
const schema = { | ||
title: 'integer', | ||
type: 'integer' | ||
} | ||
|
||
const validate = validator(schema) | ||
const stringify = build(schema) | ||
const output = stringify(1615) | ||
|
||
t.equal(output, '1615') | ||
t.ok(validate(JSON.parse(output)), 'valid schema') | ||
}) | ||
|
||
test(`render an object with an integer as JSON`, (t) => { | ||
t.plan(2) | ||
|
||
const schema = { | ||
title: 'object with integer', | ||
type: 'object', | ||
properties: { | ||
id: { | ||
type: 'integer' | ||
} | ||
} | ||
} | ||
|
||
const validate = validator(schema) | ||
const stringify = build(schema) | ||
const output = stringify({ | ||
id: 1615 | ||
}) | ||
|
||
t.equal(output, '{"id":1615}') | ||
t.ok(validate(JSON.parse(output)), 'valid schema') | ||
}) | ||
|
||
test(`render an array with an integer as JSON`, (t) => { | ||
t.plan(2) | ||
|
||
const schema = { | ||
title: 'array with integer', | ||
type: 'array', | ||
items: { | ||
type: 'integer' | ||
} | ||
} | ||
|
||
const validate = validator(schema) | ||
const stringify = build(schema) | ||
const output = stringify([1615]) | ||
|
||
t.equal(output, '[1615]') | ||
t.ok(validate(JSON.parse(output)), 'valid schema') | ||
}) | ||
|
||
test(`render an object with an additionalProperty of type integer as JSON`, (t) => { | ||
t.plan(2) | ||
|
||
const schema = { | ||
title: 'object with integer', | ||
type: 'object', | ||
additionalProperties: { | ||
type: 'integer' | ||
} | ||
} | ||
|
||
const validate = validator(schema) | ||
const stringify = build(schema) | ||
const output = stringify({ | ||
num: 1615 | ||
}) | ||
|
||
t.equal(output, '{"num":1615}') | ||
t.ok(validate(JSON.parse(output)), 'valid schema') | ||
}) |