Skip to content
This repository has been archived by the owner on Jul 20, 2019. It is now read-only.

Commit

Permalink
Refactored label tests (#6).
Browse files Browse the repository at this point in the history
  • Loading branch information
jameswilddev committed May 27, 2019
1 parent 35aad94 commit 30d6069
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
12 changes: 1 addition & 11 deletions src/label.tests.ts
Expand Up @@ -3,15 +3,5 @@ import * as label from "./label"
import * as shared from "./shared.tests"

describe(`label`, () => {
shared.run(shared.nonArrays, value => shared.rejects(
label.schema, value, `instance`, `is not of a type(s) array`
))
shared.run(shared.emptyArrays, value => shared.accepts(label.schema, value))
shared.testLabelPart(label.schema, instance => [instance], `instance[0]`)
describe(`example`, () => shared.accepts(label.schema, [
[`for_eg`, `la_run`, `mu_par`],
[],
[`just_1`],
[`long_w`, `2thetp`, `wanna_`, `depest`, `lore__`]
]))
shared.testLabel(label.schema, value => value, `instance`)
})
18 changes: 18 additions & 0 deletions src/shared.tests.ts
Expand Up @@ -802,3 +802,21 @@ export function testLabelPart(
describe(`multiple identifiers`, () => accepts(schema, instanceFactory([`for_eg`, `val_id`, `like__`, `__this`])))
describe(`duplicate identifiers`, () => accepts(schema, instanceFactory([`for_eg`, `val_id`, `like__`, `val_id`, `__this`])))
}

export function testLabel(
schema: jsonschema.Schema,
instanceFactory: InstanceFactory,
property: string
): void {
run(nonArrays, value => rejects(
schema, instanceFactory(value), property, `is not of a type(s) array`
))
run(emptyArrays, value => accepts(schema, instanceFactory(value)))
testLabelPart(schema, value => instanceFactory([value]), `${property}[0]`)
describe(`example`, () => accepts(schema, instanceFactory([
[`for_eg`, `la_run`, `mu_par`],
[],
[`just_1`],
[`long_w`, `2thetp`, `wanna_`, `depest`, `lore__`]
])))
}

0 comments on commit 30d6069

Please sign in to comment.