dart-archive / polymer_elements

https://pub.dartlang.org/packages/polymer_elements
BSD 3-Clause "New" or "Revised" License
24 stars 17 forks source link

Add helper for mocking server responses in tests #16

Open jakemac53 opened 9 years ago

jakemac53 commented 9 years ago

Currently the iron-request, iron-ajax, and iron-form tests are actually serving static files instead of using a mock server. This only supports GET requests, and doesn't allow us to modify response headers/etc, so some tests are being skipped.

This might be a bit complicated since all requests are actually coming from the JS side of things. Might be easiest to just provide a wrapper around a JS mocking library?

jakemac53 commented 9 years ago

I did bring in sinon.js which can do this, see dart wrapper here and documentation here. This is the same library that polymer js uses, so it should be relatively straightforward to port tests.

ErikGrimes commented 9 years ago

In the long run, maybe it makes sense to have a package that supports testing web components? I could see it including server mocking and custom matchers (hasChild, attributeExists ,etc) to make testing web components a first class experience.

ErikGrimes commented 9 years ago

I ran across Polymer's Web Component Tester. It looks a lot like test, but it adds fixtures, sinon, and a few other things specific to testing web components. I wonder if polymer-dart might add these things in a testing library similar to what dart-lang/http does with its http.testing library.

jakemac53 commented 9 years ago

The normal test package covers a lot of what that does, but we could possibly expose the test/common.dart file in this package externally. We would probably need to fully flush out the sinon.js wrapper though.

ErikGrimes commented 9 years ago

I published a package wrapping Pretender, a JavaScript server mocking library. It works well for mocking server responses for javascript-based Polymer Elements and has a smaller surface area than sinon. Might be useful if you don't want to wrap sinon.

Andersmholmgren commented 9 years ago

I'm just starting to looking into porting my polymer 0.5 app to 1.0 and was curious about what was happening with the WCT in Dart. From the videos from the polymer summit it seemed rather useful but of course was in JS (bleh). A darty version would be interesting

jakemac53 commented 9 years ago

The vanilla test package in dart gives you almost everything that WCT does, so it hasn't been a priority.

Andersmholmgren commented 9 years ago

Then even better. No need to port it