Skip to content

Instantly share code, notes, and snippets.

@btelles
Created November 30, 2015 23:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save btelles/649daba442725b7ad613 to your computer and use it in GitHub Desktop.
Save btelles/649daba442725b7ad613 to your computer and use it in GitHub Desktop.
When writing a test that needs to speak to an appengine endpoint, it's difficult to make the test wait for a response from a server. I've tried a bunch of permutations on waiting for "ready" on various elements, and triggering stuff. but I keep having to go back to writing a custom event and triggering it as below. Is there an easier way to wait…
<test-fixture id="basic">
<template>
<r-api path="api.widget.list"></r-api>
</template>
</test-fixture>
<dom-module id="fake-google-api">
<template>
<iron-ajax id="widgetList"
auto
url="testdata/widget.list.json"
handle-as="json"
on-response="handleResponse"></iron-ajax>
</template>
</dom-module>
<script>
Polymer({
is: 'fake-google-api',
properties: {
widgetListData: {
type: Object,
value: {}
}
},
handleResponse: function(request) {
if(this.id === 'widgetapi') {
this.set('widgetListData', request.detail.response);
this.fire('google-api-load');
}
},
listeners: {
'test': 'executeTests' // I shouldn't need to create this listener.
},
});
suite('r-api tests', function() {
var element;
setup(function() {
replace('google-client-loader').with('fake-google-api');
element = fixture('basic');
});
test('Gets a simple widget.list endpoint response', function(done) {
element.$.widgetapi.executeTests = function() { // I shouldn't have to write this custom event.
flush( function() {
assert.deepEqual(element.result, {widgets: ['1', '2']});
done();
});
}.bind(this);
});
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment