Created
November 30, 2015 23:50
-
-
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…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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