-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Mocha/Chai Promise Adapter -- Proof of Concept #47
Conversation
@@ -0,0 +1,104 @@ | |||
/** | |||
* Adapts Jasmine-Node tests to work better with WebDriverJS. Borrows |
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.
Update comment :)
Cool! Nice start. Sorry for the slow response on this! I think the biggest issue here will be to figure out how to reuse the mocha support that WebdriverJS already has build in - check out https://code.google.com/p/selenium/source/browse/javascript/node/selenium-webdriver/testing/index.js That doesn't have any of the chai/promise support, but it does take care of wrapping the global functions. |
@juliemr I looked at WebdriverJS code you linked to. They take the approach of not clobbering mochas global functions, and instead expect you to Rather than this: describe('My Module', function () {
it('does something', function () {
//expectations
}
}); Code using their adapter looks like this: var test = require('selenium-webdriver/testing');
test.describe('My Module', function() {
test.it('does something', function() {
//expectations
}
}); If we want to overwrite the global functions, my adapter can be reduced to a series of statements like this: var test = require('selenium-webdriver/testing');
global.describe = test.describe;
global.it = test.it;
//.... etc As for expectations, I am going to continue working on the chai promise adapter to get it where I think it needs to be. I will keep you posted. |
Bump. Has there been any progress on this? Would love to see Mocha and Chai better integrated with Protractor. |
+1. Chai expect library is much better than jasmine's IMO. I want to be able to do expect(promise).to.have.property('foo', 'bar') where I can't seem to do this in jasmine without writing custom matchers. |
See 478c00a What's the status of the promise adapters for chai? Could we make them work with the new commit? |
Also found this thing: http://chaijs.com/plugins/chai-as-promised |
chai-as-promised was recently rewritten to address my one major issue with it (it broke integration with many other chai plugins). I haven't used the new version yet, but it's certainly worth checking out. |
Chai As Promised seems to work, but I didn't try with any other plugins. Check out https://github.com/angular/protractor/blob/master/docs/using-mocha.md and the test it links to. I think that takes care of everything from this PR - but let me know if there's any lingering issues or missing features! |
Looks good to me. I'm closing the issue for now. |
Fixes #35
I put this together fairly quickly, but I wanted to run it by the protractor team before I invested more time. It makes use of my promise-testing library to provide a Chai.js adapter for expectations on webdriver promises, very similar to the existing Jasmine implementation.
All the relevant files are in the
mochachaiwd
directory.onMocha.js
andindex.js
are modified copies of files with the same name elsewhere in the project. I recommend using a file comparison tool to see what I actually changed (it's really only a few lines).After cloning, switch to the
mocha-proof-of-concept
branch and then:Once selenium is up and running, then:
This is not ready for primetime yet. To get there it needs:
mochachaiwd/index.js
is a hacked copy ofjasminewd/index.js
. There is plenty of duplicate code that could easily be eliminated.expect(promiseA).to.equal(promiseB)
). This will be harder to patch in Chai than it was Jasmine, since Chai allows such long promise chains (expect({a:10}).property('a').to.be.at.least(6)
). I will add the feature there (possibly include a hook for customizing how promises are detected - which protractor could use to detect webdriver promises).Thanks for for a great tool guys!