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

deepEqual null handling #22

Merged
merged 5 commits into from
Jan 3, 2018
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
4 changes: 1 addition & 3 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const path = require('path')
const merge = require('merge-stream')
const babel = require('gulp-babel')
const typescript = require('gulp-typescript')
const flowgen = require('gulp-flowgen')

const tsOptions = require('./tsconfig.json').compilerOptions
const tsProject = typescript.createProject(tsOptions)
Expand All @@ -27,8 +26,7 @@ const build = () => {

return merge(
tsResult.js.pipe(babel()),
tsResult.dts,
tsResult.dts.pipe(flowgen())
tsResult.dts
)
.pipe(gulp.dest(tsOptions.outDir))
}
Expand Down
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,15 @@
"license": "MIT",
"dependencies": {},
"devDependencies": {
"@types/jest": "^19.2.2",
"@types/jest": "^22.0.0",
"babel-plugin-transform-object-assign": "^6.22.0",
"babel-preset-latest": "^6.16.0",
"gulp": "gulpjs/gulp#4.0",
"gulp-babel": "^6.1.2",
"gulp-flowgen": "^0.0.3",
"gulp-typescript": "^3.1.4",
"jest": "^19.0.2",
"jest": "^22.0.4",
"merge-stream": "^1.0.1",
"ts-jest": "^19.0.9",
"ts-jest": "^22.0.0",
"tslint": "^5.1.0",
"typescript": "^2.1.4"
},
Expand Down
3 changes: 3 additions & 0 deletions src/deepEqual.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ const deepEqual = (a: any, b: any) => {
if (typeof a !== typeof b)
return false

if ((a === null || b === null) && a !== b)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No big deal, but the a !== b is redundant, I believe (since it's already established by the first if).

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah did that too late in the night. I fix that before the realease.

return false

if (Array.isArray(a))
return arrayEqual(a, b)

Expand Down
8 changes: 8 additions & 0 deletions src/tests/deepEqual.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,11 @@ it('handles functions', () => {
expect(deepEqual(a, b)).toBe(false)
expect(deepEqual(a, a)).toBe(true)
})

it('handles null objects', () => {
expect(deepEqual(null, null)).toBe(true)
expect(deepEqual(null, 42)).toBe(false)
expect(deepEqual(null, '')).toBe(false)
expect(deepEqual(null, {})).toBe(false)
expect(deepEqual(null, { a: 42 })).toBe(false)
})
Loading