javascript - How do assertion libraries such as Chai work without forcing a call to a function? -
in chai, can stuff following:
expect({}).to.exist;
exist
not function call, still works in testing frameworks. opposite (expect({}).to.not.exist
) causes tests fail, again, exist
not function call.
how these assertions work without making me call function? in fact, if try expect({}).to.exist()
test fails because exist
not function.
i figured out (or @ least, figured out a method). use javascript getters:
var throws = { a() { throw new error('a'); }, b() { throw new error('b'); }, c() { throw new error('c'); } };
when doing throws.a
, throws.b
, or throws.c
, appropriate error thrown.
from point rather easy build assertions contained within chai.
Comments
Post a Comment