-
-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fallback to setTimeout if requestAnimationFrame is not present
This is mostly to allow tests to run in PhantomJS without requring a 'requestAnimationFrame' pollyfill. Closes #43. The weirdness in the test is because there is no way currently to make sure the component is cleared and destroyed before the module's teardown hook is called. Wrapping the component in an if is a workaround until this: https://github.com/switchfly/ember-test-helpers/pull/147/files lands.
- Loading branch information
Showing
4 changed files
with
76 additions
and
8 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import Ember from 'ember'; | ||
import { test, moduleForComponent } from 'ember-qunit'; | ||
import { generateContent, sortItemsByPosition } from '../helpers/helpers'; | ||
import hbs from 'htmlbars-inline-precompile'; | ||
|
||
let originalRaf = window.requestAnimationFrame; | ||
|
||
let template = hbs`{{#if showComponent}} | ||
<div style={{size-to-style width height}}> | ||
{{#ember-collection | ||
items=content | ||
cell-layout=(fixed-grid-layout itemWidth itemHeight) | ||
estimated-width=width | ||
estimated-height=height | ||
scroll-left=offsetX | ||
scroll-top=offsetY | ||
buffer=buffer | ||
class="ember-collection" | ||
as |item| ~}} | ||
<div class="list-item">{{item.name}}</div> | ||
{{~/ember-collection~}} | ||
</div> | ||
{{/if}}`; | ||
|
||
moduleForComponent('ember-collection', 'raf', { | ||
integration: true, | ||
setup: function() { | ||
window.requestAnimationFrame = undefined; | ||
}, | ||
teardown: function() { | ||
window.requestAnimationFrame = originalRaf; | ||
} | ||
}); | ||
|
||
test('works without requestAnimationFrame', function(assert) { | ||
|
||
var width = 150, height = 500, itemWidth = 50, itemHeight = 50; | ||
var offsetY = 100; | ||
var content = generateContent(5); | ||
|
||
this.setProperties({ width, height, itemWidth, itemHeight, content, offsetY, showComponent: true }); | ||
this.render(template); | ||
var positionSorted = sortItemsByPosition(this); | ||
|
||
assert.equal( | ||
Ember.$(positionSorted[0]).text().trim(), | ||
"Item 1", "We rendered without requestAnimationFrame" | ||
); | ||
|
||
// Force the component to be torn down. | ||
this.setProperties({showComponent: false}); | ||
}); |
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