Skip to content

Refactor: Improve console logger clarity and test coverage #24

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

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 0 additions & 2 deletions src/console-logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,3 @@ export const consoleLogger = (message: string) => <T>(source: Observable<T>) =>
}
})
)

export const debug = consoleLogger
16 changes: 11 additions & 5 deletions test/console-logger.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ import { expect } from 'chai'
import { TestScheduler } from 'rxjs/testing'
import { assert, createSandbox, SinonSandbox, SinonStub } from 'sinon'

import { debug } from '../src/console-logger'
import { consoleLogger } from '../src/console-logger'

describe('debug', () => {
describe('consoleLogger', () => {
let scheduler: TestScheduler
let sb: SinonSandbox

let errorStub: SinonStub
let logStub: SinonStub
let groupStub: SinonStub
let groupEndStub: SinonStub

beforeEach(() => {
scheduler = new TestScheduler((actual, expected) => void expect(actual).to.deep.equal(expected))
Expand All @@ -20,6 +22,8 @@ describe('debug', () => {

errorStub = sb.stub(console, 'error')
logStub = sb.stub(console, 'log')
groupStub = sb.stub(console, 'group')
groupEndStub = sb.stub(console, 'groupEnd')
})

afterEach(() => {
Expand All @@ -32,11 +36,13 @@ describe('debug', () => {

const message = 'Test Message'

scheduler.expectObservable(source.pipe(debug(message))).toBe(expected)
scheduler.expectObservable(source.pipe(consoleLogger(message))).toBe(expected)
scheduler.flush()
assert.notCalled(errorStub)
assert.callCount(logStub, 3)
assert.calledWith(logStub, message)
assert.callCount(logStub, 2)
assert.calledWith(logStub, message.concat(' Completed.'))
assert.calledOnce(groupStub)
assert.calledWith(groupStub, message)
assert.calledOnce(groupEndStub)
})
})