-
-
Save joepie91/381ec3d9061d308aec08460e747e313f to your computer and use it in GitHub Desktop.
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
"use strict"; | |
const expect = require("chai").expect; | |
const dm = require("../src"); | |
let User = dm.createType("User", { | |
messages: dm.arrayOf(dm.string()) | |
}); | |
describe("guarded arrays", () => { | |
let joe = User({ | |
messages: [] | |
}); | |
it("should accept valid values", () => { | |
joe.messages.push("Hello world!"); | |
expect(joe.messages[0]).to.equal("Hello world!"); | |
joe.messages.splice(0, 0, "Hello earth!") | |
expect(joe.messages[0]).to.equal("Hello earth!"); | |
expect(joe.messages[1]).to.equal("Hello world!"); | |
joe.messages[0] = "Hello moon!"; | |
console.log(joe.messages); | |
expect(joe.messages[0]).to.equal("Hello moon!"); | |
expect(joe.messages[1]).to.equal("Hello world!"); | |
}); | |
it("should reject invalid values", () => { | |
expect(() => { | |
joe.messages.push(42); | |
}).to.throw("Expected a string, got a number instead"); | |
expect(() => { | |
joe.messages.splice(0, 0, 43); | |
}).to.throw("Expected a string, got a number instead"); | |
expect(() => { | |
joe.messages[0] = 44; | |
}).to.throw("Expected a string, got a number instead"); | |
expect(joe.messages[0]).to.equal("Hello moon!"); | |
expect(joe.messages[1]).to.equal("Hello world!"); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment