Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit126ae45

Browse files
committed
tests: use tape instead of assert lib
- because Node maintainers say not to use assert- because assert is buggy and frozen- because tape enables us to nest tests for greater readability
1 parentf28b3d0 commit126ae45

File tree

2 files changed

+58
-51
lines changed

2 files changed

+58
-51
lines changed

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description":"a tiny lib for creating state machines as swappable Redux reducers",
55
"main":"index.js",
66
"scripts": {
7-
"test":"node test.js"
7+
"test":"node test.js | faucet"
88
},
99
"repository": {
1010
"type":"git",

‎test.js‎

Lines changed: 57 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"use strict"
22

33
const{ createMachine}=require('./index.js')
4-
constassert=require('assert')
4+
consttest=require('tape')
55

66
// BEGIN FIXTURES
77

@@ -45,68 +45,75 @@ const fetchUsersReducer = createMachine({
4545

4646
// END FIXTURES
4747

48-
// BEGIN HELPERS
48+
// run the reducer and go through several status transitions
49+
// to test a typical scenario—making an API call
4950

50-
letstate=undefined
51-
letprevState=undefined
51+
test('should transition between states',t=>{
5252

53-
constaction=(type,payload)=>{
54-
prevState=state
55-
state=fetchUsersReducer(state,{type, payload})
56-
}
53+
letstate=undefined
54+
letprevState=undefined
5755

58-
constexpect=(expected,maybeMessage)=>assert.deepEqual(state,expected,maybeMessage)
56+
constexpect=(expected,maybeMessage)=>t.deepEquals(state,expected,maybeMessage)
5957

60-
// END HELPERS
58+
constaction=(type,payload)=>{
59+
prevState=state
60+
state=fetchUsersReducer(state,{type, payload})
61+
}
6162

62-
// run the reducer and go through several status transitions
63-
// to test a typical scenario—making an API call
63+
action('DUMMY')
64+
expect({
65+
status:'INIT',
66+
},'Should set initial status to "INIT"')
6467

65-
action('DUMMY')
66-
expect({
67-
status:'INIT',
68-
},'Should set initial status to "INIT"')
68+
action('FETCH_USERS_RESPONSE',{users})
69+
expect(prevState,'Should ignore messages when not handled by current status')
6970

70-
action('FETCH_USERS_RESPONSE',{users})
71-
expect(prevState,'Should ignore messages when not handled by current status')
71+
action('FETCH_USERS')
72+
expect({
73+
error:null,
74+
status:'IN_PROGRESS'
75+
})
7276

73-
action('FETCH_USERS')
74-
expect({
75-
error:null,
76-
status:'IN_PROGRESS'
77-
})
77+
action('FETCH_USERS_FAIL','timeout')
78+
expect({
79+
error:'timeout',
80+
status:'INIT'
81+
})
7882

79-
action('FETCH_USERS_FAIL','timeout')
80-
expect({
81-
error:'timeout',
82-
status:'INIT'
83-
})
83+
action('FETCH_USERS')
84+
expect({
85+
error:null,
86+
status:'IN_PROGRESS'
87+
})
8488

85-
action('FETCH_USERS')
86-
expect({
87-
error:null,
88-
status:'IN_PROGRESS'
89-
})
89+
action('FETCH_USERS')
90+
expect(prevState)
9091

91-
action('FETCH_USERS')
92-
expect(prevState)
92+
action('FETCH_USERS_RESPONSE',{users})
93+
expect({
94+
error:null,
95+
status:'INIT',
96+
users
97+
})
9398

94-
action('FETCH_USERS_RESPONSE',{users})
95-
expect({
96-
error:null,
97-
status:'INIT',
98-
users
99+
t.end()
99100
})
100101

101-
assert.throws(
102-
()=>{
103-
letstore={status:'STATUS_NOT_IN_CREATE_MACHINE'}
104-
constreducer=createMachine({})
105-
store=reducer(store,{type:'DUMMY'})
102+
test('should error on status not found',t=>{
103+
letstore={status:'STATUS_NOT_IN_CREATE_MACHINE'}
104+
constreducer=createMachine({})
105+
leterror
106+
try{
107+
reducer(store,{type:'DUMMY'})
108+
}
109+
catch(err){
110+
error=err
111+
}
106112

107-
},
108-
err=>err.message==='reducersObject missing reducer for status STATUS_NOT_IN_CREATE_MACHINE',
109-
'should error whenstatusnot found'
110-
)
113+
t.equals(
114+
error.message,
115+
'reducersObject missing reducer forstatusSTATUS_NOT_IN_CREATE_MACHINE'
116+
)
111117

112-
console.log('success')
118+
t.end()
119+
})

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp