Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(compose): a move comprehensive test cases #198

Merged
merged 1 commit into from
May 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 41 additions & 2 deletions src/compose.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,30 +130,69 @@ describe('Compose', function () {
return x && typeof x.then === 'function'
}

it('should work', async () => {
it('should get executed order one by one', async () => {
const arr: number[] = []
const stack = []
const called: boolean[] = []

stack.push(async (context: C, next: Function) => {
called.push(true)

arr.push(1)
await next()
arr.push(6)
})

stack.push(async (context: C, next: Function) => {
called.push(true)

arr.push(2)
await next()
arr.push(5)
})

stack.push(async (context: C, next: Function) => {
called.push(true)

arr.push(3)
await next()
arr.push(4)
})

await compose(stack)({})
expect(called).toEqual([true, true, true])
expect(arr).toEqual([1, 2, 3, 4, 5, 6])
})

it('should not get executed if previous next() not triggered', async () => {
const arr: number[] = []
const stack = []
const called: boolean[] = []

stack.push(async (context: C, next: Function) => {
called.push(true)

arr.push(1)
await next()
arr.push(6)
})

stack.push(async (context: C, next: Function) => {
called.push(true)
arr.push(2)
})

stack.push(async (context: C, next: Function) => {
called.push(true)

arr.push(3)
await next()
arr.push(4)
})

await compose(stack)({})
expect(arr).toEqual(expect.arrayContaining([1, 2, 3, 4, 5, 6]))
expect(called).toEqual([true, true])
expect(arr).toEqual([1, 2, 6])
})

it('should be able to be called twice', () => {
Expand Down
5 changes: 3 additions & 2 deletions tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"src/**/*"
],
"exclude": [
"src/**/*.test.ts"
"src/**/*.test.ts",
"src/router/reg-exp-router/*"
]
}
}