-
Notifications
You must be signed in to change notification settings - Fork 19
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
Adding Jest #40
Adding Jest #40
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Jest is compelling, and I will add a few snapshot tests in a follow-up.
let's hold off on merging this until #19 is merged, in order to migrate its tests to Jest as well.
test/helpers.test.js
Outdated
}; | ||
const data = { foo: 'bar' }; | ||
const { firstChild } = parseXML('<a x="1" y="two">hello</a>'); | ||
visitNode(firstChild, 0, converters, data); | ||
sinon.assert.calledWith(converters.a, { x: '1', y: 'two' }, data); | ||
expect(converters.a.mock.calls.length).toBe(1); | ||
expect(converters.a.mock.calls[0][0]).toEqual({ x: '1', y: 'two' }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
interesting, mocking in Jest will be different -- i like it!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can also write:
expect(converters.a).toHaveBeenCalledTimes(1);
expect(converters.a).toHaveBeenCalledWith({ x: '1', y: 'two' });
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pgoldrbx - yes, certainly. fixed.
package.json
Outdated
@@ -15,7 +15,8 @@ | |||
"lint": "eslint .", | |||
"prepublishOnly": "npm run clean && npm run build", | |||
"pretest": "eslint .", | |||
"test": "nyc mocha --require babel-register --recursive" | |||
"test": "jest --silent=true", | |||
"test-watch": "jest --silent=true --watch" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
v.minor, there's an extra space after jest
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch :)
test/XMLToReact.test.js
Outdated
@@ -43,37 +41,37 @@ describe('XMLToReact class ', () => { | |||
}; | |||
|
|||
it('exports a module', () => { | |||
expect(XMLToReact).to.be.a('function'); | |||
expect(XMLToReact).toEqual(expect.any(Function)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
personally i'm fine with (typeof x).toEqual('function')
as a pattern as well - but the mater works too :)
test/XMLToReact.test.js
Outdated
expect(wrapper.exists()).to.equal(true); | ||
expect(wrapper.find('.test > [fancy]')).to.have.length(1); | ||
expect(visitNodeSpy.called).to.equal(true); | ||
expect(wrapper.exists()).toBeTruthy(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about .toEqual(true)
for equivalent testing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will resolve to use just .toEqual(true)
@@ -82,8 +80,8 @@ describe('XMLToReact class ', () => { | |||
const xmltoreact = new XMLToReact(converters); | |||
const tree = xmltoreact.convert(badXML); | |||
|
|||
expect(tree).to.equal(null); | |||
expect(visitNodeSpy.called).to.equal(false); | |||
expect(tree).toEqual(null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
trivial - in some assertions below you use toBeNull
- make it consistent? (i don't really care)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed to .toEqual(null)
everywhere
test/helpers.test.js
Outdated
@@ -34,7 +32,7 @@ describe('helpers', () => { | |||
bar: () => {}, | |||
baz: () => {}, | |||
}; | |||
expect(validateConverters(converters)).to.equal(true); | |||
expect(validateConverters(converters)).toBeTruthy(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
my comments are still the same here - i'd like to see strict boolean assertion, .toEqual(true)
for this and all below (everywhere)
test/helpers.test.js
Outdated
expect(validateConverters(true)).to.equal(false); | ||
expect(validateConverters(() => {})).to.equal(false); | ||
expect(validateConverters(null)).to.equal(false); | ||
expect(validateConverters()).not.toEqual(true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't we just expect .toEqual(false)
in this case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤡
* add environment and dependency prerequisites to README.md * change test command in readme * updated prerequisites * added testing and development environment details for CONTRIBUTING.md * change prerequisites to read as a sentence * Update CONTRIBUTING.md * update attribution heading for CONTRIBUTORING.md
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm! 🤡
@gautamarora ah, codeship is failing on lint issues!
|
@gautamarora looks like this one is good to merge? |
* Move xmldom parsing to internal interface * fix lint errors * add changelog update
merged! |
into feature/jest * 'feature/jest' of https://github.com/CondeNast/xml-to-react: linter strikes again Updating mock call checks Fix linting issues Making jest go faster + have cov thresholds Fix "not equal to true" tests to be "equal to false" Replace toBeTruthy()/toBeNull() with strict boolean checks Replace toBeTruthy()/toBeNull() with strict boolean checks Adding Jest
into feature/jest * 'feature/jest' of https://github.com/CondeNast/xml-to-react: Fix linting issues Making jest go faster + have cov thresholds Replace toBeTruthy()/toBeNull() with strict boolean checks Replace toBeTruthy()/toBeNull() with strict boolean checks Adding Jest linter strikes again Updating mock call checks Fix linting issues Making jest go faster + have cov thresholds Fix "not equal to true" tests to be "equal to false" Replace toBeTruthy()/toBeNull() with strict boolean checks Replace toBeTruthy()/toBeNull() with strict boolean checks Adding Jest
@@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. | |||
|
|||
## [Unreleased] | |||
- Initial Release | |||
- Changed XML parsing to use an internal interface. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤷♂️ still part of our initial release
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤷♂️
package.json
Outdated
@@ -15,7 +15,8 @@ | |||
"lint": "eslint .", | |||
"prepublishOnly": "npm run clean && npm run build", | |||
"pretest": "eslint .", | |||
"test": "nyc mocha --require babel-register --recursive" | |||
"test": "jest --silent=true", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
trivial, extra space after jest
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed!
@@ -0,0 +1,33 @@ | |||
import { DOMParser } from 'xmldom'; | |||
|
|||
export const ERR_INVALID_XML = 'XMLToReact: Unable to parse invalid XML input. Please input valid XML.'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
did this not get rebased properly? is that why it's showing up in this PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, not sure what happened here, certainly was rebased.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i added a // eslint-disable-line no-console
for the console.warn, but nothing else.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmmm... because this was merged to master already
a08a366
it's not a big deal but i guess you have a merge commit in here or something
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm - a couple minor things but nothing blocking merge
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think this is good to go. let's do it!
A exploratory PR for using Jest for testing and coverage.
Description
This PR replaces chai, mocha, sinon, nyc with jest.
Types of changes
Related Issue
#37
Motivation and Context
Some of the pros of using Jest would be:
How Has This Been Tested?
npm test
npm run test:watch
Screenshots (if appropriate):
Checklist:
p.s. Force push closed my last PR #38 😞 , so creating a new one.