Skip to content

Commit

Permalink
Refactor tests
Browse files Browse the repository at this point in the history
  • Loading branch information
keenondrums committed Jan 9, 2019
1 parent c1be4e8 commit aa33d0a
Showing 1 changed file with 17 additions and 20 deletions.
37 changes: 17 additions & 20 deletions index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,26 @@ import { expect } from 'chai'

import { ActionStandard, prefix } from './index'

// From https://github.com/reduxjs/redux/blob/master/src/utils/isPlainObject.js
const isPlainObject = (obj: any) => {
if (typeof obj !== 'object' || obj === null) return false

let proto = obj
while (Object.getPrototypeOf(proto) !== null) {
proto = Object.getPrototypeOf(proto)
}

return Object.getPrototypeOf(obj) === proto
}

// tslint:disable max-classes-per-file
describe(ActionStandard.name, () => {
describe('prefix', () => {
it('exists', () => {
class Test extends ActionStandard {}
const test = new Test()
expect(test.type.startsWith(prefix)).to.be.equal(true)
expect(isPlainObject(test)).to.be.equal(true)
})
it('can be changed', () => {
const prefixNew = 'test'
Expand All @@ -17,6 +30,7 @@ describe(ActionStandard.name, () => {
}
const test = new Test()
expect(test.type.startsWith(prefixNew)).to.be.equal(true)
expect(isPlainObject(test)).to.be.equal(true)
})
it('can be inherited', () => {
const prefixNew = 'test'
Expand All @@ -26,6 +40,7 @@ describe(ActionStandard.name, () => {
class TestChild extends TestParent {}
const test = new TestChild()
expect(test.type.startsWith(prefixNew)).to.be.equal(true)
expect(isPlainObject(test)).to.be.equal(true)
})
})

Expand All @@ -35,12 +50,14 @@ describe(ActionStandard.name, () => {
const test = new Test()
expect(Test.type.endsWith('Test')).to.be.equal(true)
expect(test.type.endsWith('Test')).to.be.equal(true)
expect(isPlainObject(test)).to.be.equal(true)
})
it("is prefix with class' name", () => {
class Test extends ActionStandard {}
const test = new Test()
expect(Test.type).to.be.equal(`${prefix}Test`)
expect(test.type).to.be.equal(`${prefix}Test`)
expect(isPlainObject(test)).to.be.equal(true)
})
})

Expand Down Expand Up @@ -86,24 +103,4 @@ describe(ActionStandard.name, () => {
expect(test.error).to.be.equal(true)
})
})

describe('redux integration', () => {
// From https://github.com/reduxjs/redux/blob/master/src/utils/isPlainObject.js
const isPlainObject = (obj: any) => {
if (typeof obj !== 'object' || obj === null) return false

let proto = obj
while (Object.getPrototypeOf(proto) !== null) {
proto = Object.getPrototypeOf(proto)
}

return Object.getPrototypeOf(obj) === proto
}

it('is plain object', () => {
class Test extends ActionStandard {}
const test = new Test()
expect(isPlainObject(test)).to.be.equal(true)
})
})
})

0 comments on commit aa33d0a

Please sign in to comment.