-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest.js
More file actions
40 lines (27 loc) · 1.47 KB
/
test.js
File metadata and controls
40 lines (27 loc) · 1.47 KB
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
34
35
36
37
38
39
const test = require('tape');
const stampit = require('stampit');
const errorMessage = 'Method \'%methodName%\' needs to be implemented.';
const InterfaceCheck = require('./index');
const InterfaceWithTwoMethods = stampit().compose(InterfaceCheck).methods({foo: () => {}, bar: () => {}});
test('is a stamp', function (t) {
t.equal(typeof InterfaceCheck.fixed, 'object');
t.end();
});
test('creation of stamp that implements interface check with two unimplemented methods throws error', (t) => {
const ImplementationWithoutImplementedMethod =
stampit().compose(InterfaceWithTwoMethods).methods({});
t.throws(ImplementationWithoutImplementedMethod, new RegExp(errorMessage.replace('%methodName%', 'foo')));
t.end();
});
test('creation of stamp that implements interface check with one unimplemented method throws error', (t) => {
const ImplementationWithoutImplementedMethod =
stampit().compose(InterfaceWithTwoMethods).methods({foo: () => {return this;}});
t.throws(ImplementationWithoutImplementedMethod, new RegExp(errorMessage.replace('%methodName%', 'bar')));
t.end();
});
test('creation of stamp that implements interface check with two implemented methods doesn\'t throw error', (t) => {
const ImplementationWithImplementedMethod =
stampit().compose(InterfaceWithTwoMethods).methods({foo: () => {return this;}, bar: () => {return this;}});
t.doesNotThrow(ImplementationWithImplementedMethod);
t.end()
});