UNPKG

1.57 kBtext/coffeescriptView Raw
1{ipso, mock, Mock, define} = require 'ipso'
2
3before ipso ->
4
5 #
6 # create a mock to be returned by the module function
7 #
8
9 mock( 'nonExistant' ).with
10
11 function1: ->
12 property1: 'value1'
13
14 define
15
16 #
17 # define the module
18 #
19 # * get() is defined on the scope of the
20 # exporter that creates the stub module,
21 #
22 # * it returns the specified mock
23 #
24
25 '$non-existant': -> return get 'nonExistant'
26
27 #
28 # define node_module called 'missing' with
29 # 2 exported classes
30 #
31
32 missing: ->
33
34 ClassName: Mock 'ClassName'
35 Another: Mock 'Another'
36
37
38
39it "has created ability to require 'non-existant' in module being tested",
40
41 ipso (nonExistant, should) ->
42
43 nonExistant.does function2: ->
44 non = require 'non-existant'
45
46 # console.log require 'missing'
47
48 # console.log non()
49
50 #
51 # => { function1: [Function],
52 # property1: 'value1',
53 # function2: [Function] }
54 #
55
56 non().function2()
57
58
59
60it "can require 'missing' and create expectations on the Class / instance",
61
62 ipso (ClassName, should) ->
63
64 ClassName.does
65
66 constructor: (arg) -> arg.should.equal 'ARG'
67 someFunction: ->
68
69
70
71
72 #
73 # this would generally be elsewhere (in the module being tested)
74 #
75
76 missing = require 'missing'
77 instance = new missing.ClassName 'ARG'
78 instance.someFunction()
79