Last active
February 5, 2019 01:59
-
-
Save w1shen/8eee4752f291a0441777533931e9d630 to your computer and use it in GitHub Desktop.
New Twiddle
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
import $ from 'jquery'; | |
import { module, test } from 'qunit'; | |
import { setupRenderingTest } from 'ember-qunit'; | |
import { settled } from '@ember/test-helpers'; | |
import { later } from '@ember/runloop'; | |
import { registerWaiter } from '@ember/test'; | |
import Pretender from 'pretender'; | |
const DELAY = 2000; | |
module('Integration | Component | settled-exam', function(hooks) { | |
setupRenderingTest(hooks); | |
test('settled works with runloop', async function(assert) { | |
let isDone = false; | |
later(()=> { | |
isDone = true; | |
}, DELAY); | |
await settled(); | |
assert.ok(isDone); | |
}); | |
test('settled works with test waiters', async function(assert) { | |
let isDone = false; | |
let count = 1; | |
registerWaiter(() => count === 0); | |
setTimeout(()=> { | |
count = 0; | |
isDone = true; | |
}, DELAY); | |
await settled(); | |
assert.ok(isDone); | |
}); | |
test('settled works with jQuery.ajax', async function(assert) { | |
let isDone = false; | |
const server = new Pretender(function() { | |
this.get('/photos/:id', () => { | |
return [200, { 'Content-Type': 'application/json' }, JSON.stringify({})] | |
}, DELAY); | |
}); | |
$.get('/photos/871').then(() => { | |
isDone = true; | |
}); | |
await settled(); | |
assert.ok(isDone); | |
server.shutdown(); | |
}); | |
test('settled works with xhr', async function(assert) { | |
let isDone = false; | |
const server = new Pretender(function() { | |
this.get('/photos/:id', () => { | |
return [200, { 'Content-Type': 'application/json' }, JSON.stringify({})] | |
}, DELAY); | |
}); | |
const xhr = new XMLHttpRequest(); | |
xhr.open('GET', '/photos/871'); | |
xhr.onload = () => { | |
isDone = true; | |
}; | |
xhr.send(); | |
await settled(); | |
assert.ok(isDone); | |
server.shutdown(); | |
}); | |
test('settled works with setTimeout', async function(assert) { | |
let isDone = false; | |
setTimeout(()=> { | |
isDone = true; | |
}, DELAY); | |
await settled(); | |
assert.ok(isDone); | |
}); | |
}); |
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
import Application from '../app'; | |
import config from '../config/environment'; | |
import { setApplication } from '@ember/test-helpers'; | |
import { start } from 'ember-qunit'; | |
import { assign } from '@ember/polyfills'; | |
let attributes = assign({ rootElement: '#ember-testing', autoboot: false }, config.APP); | |
setApplication(Application.create(attributes)); | |
start(); |
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
{ | |
"version": "0.15.1", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": true | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js", | |
"ember": "3.4.3", | |
"ember-template-compiler": "3.4.3", | |
"ember-testing": "3.4.3" | |
}, | |
"addons": { | |
"ember-data": "3.4.2", | |
"ember-lifeline": "3.1.1", | |
"ember-fetch": "6.4.0", | |
"ember-cli-pretender": "3.0.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment