Skip to content
This repository has been archived by the owner on Nov 10, 2022. It is now read-only.

Commit

Permalink
refactor: simplify tests using async/await and before/after
Browse files Browse the repository at this point in the history
  • Loading branch information
severo committed Jan 22, 2020
1 parent e36e426 commit 8bb4d32
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions src/socket.io/socket.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,22 @@ describe('Server', () => {
})

describe('connect', () => {
it('should connect socket', (done: Function) => {
client.on('connect', () => {
expect(client.connected).to.be.true
client.disconnect()
done()
})
beforeEach(async () => {
await new Promise(resolve => client.on('connect', resolve))
})
it('should create a new user', () => {
new Promise(resolve => client.on('connect', resolve))
.then(() => {
const logs = mockLogger.getInfoLogs()
logs.should.include.something.that.have.string(
'New user created for socket'
)
})
.then(() => client.disconnect())
afterEach(() => {
client.disconnect()
})

it('should connect socket', async () => {
expect(client.connected).to.be.true
})
it('should create a new user', async () => {
mockLogger
.getInfoLogs()
.should.include.something.that.have.string(
'New user created for socket'
)
})
})

Expand Down

0 comments on commit 8bb4d32

Please sign in to comment.