-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate AssetReference tests from Karma to Node (#7214)
* Migrate AssetReference tests from Karma to Node * Reenable all tests * typedef -> import
- Loading branch information
1 parent
bb40a3f
commit 5729cf1
Showing
5 changed files
with
106 additions
and
100 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import { Application } from '../../../src/framework/application.js'; | ||
import { Asset } from '../../../src/framework/asset/asset.js'; | ||
import { AssetReference } from '../../../src/framework/asset/asset-reference.js'; | ||
import { NullGraphicsDevice } from '../../../src/platform/graphics/null/null-graphics-device.js'; | ||
|
||
import { Canvas } from 'skia-canvas'; | ||
import { expect } from 'chai'; | ||
import { fake, restore } from 'sinon'; | ||
|
||
describe('AssetReference', function () { | ||
let app; | ||
let parent; | ||
let load; | ||
let remove; | ||
let add; | ||
|
||
beforeEach(function () { | ||
const canvas = new Canvas(500, 500); | ||
app = new Application(canvas, { graphicsDevice: new NullGraphicsDevice(canvas) }); | ||
parent = fake(); | ||
load = fake(); | ||
remove = fake(); | ||
add = fake(); | ||
}); | ||
|
||
afterEach(function () { | ||
app.destroy(); | ||
restore(); | ||
}); | ||
|
||
it('should call load callback when asset is loaded', function (done) { | ||
const reg = new AssetReference('propName', parent, app.assets, { | ||
load: load | ||
}); | ||
|
||
const asset = new Asset('Reference Test', 'texture', { | ||
url: 'test/test-assets/test.png' | ||
}); | ||
|
||
reg.id = asset.id; | ||
|
||
asset.once('load', function () { | ||
expect(load.callCount).to.equal(1); | ||
expect(load.args[0][0]).to.equal('propName'); | ||
expect(load.args[0][1]).to.equal(parent); | ||
expect(load.args[0][2].id).to.equal(asset.id); | ||
done(); | ||
}); | ||
|
||
app.assets.add(asset); | ||
app.assets.load(asset); | ||
}); | ||
|
||
it('should call add callback when asset is added', function (done) { | ||
const reg = new AssetReference('propName', parent, app.assets, { | ||
add: add | ||
}); | ||
|
||
const asset = new Asset('Reference Test', 'texture', { | ||
url: 'test/test-assets/test.png' | ||
}); | ||
|
||
reg.id = asset.id; | ||
|
||
app.assets.once('add', function () { | ||
setTimeout(function () { | ||
expect(add.callCount).to.equal(1); | ||
expect(add.args[0][0]).to.equal('propName'); | ||
expect(add.args[0][1]).to.equal(parent); | ||
expect(add.args[0][2].id).to.equal(asset.id); | ||
done(); | ||
}, 0); | ||
}); | ||
|
||
app.assets.add(asset); | ||
}); | ||
|
||
it('should call remove callback when asset is removed', function (done) { | ||
const reg = new AssetReference('propName', parent, app.assets, { | ||
remove: remove | ||
}); | ||
|
||
const asset = new Asset('Reference Test', 'texture', { | ||
url: 'test/test-assets/test.png' | ||
}); | ||
|
||
reg.id = asset.id; | ||
|
||
asset.once('remove', function () { | ||
setTimeout(function () { | ||
expect(remove.callCount).to.equal(1); | ||
expect(remove.args[0][0]).to.equal('propName'); | ||
expect(remove.args[0][1]).to.equal(parent); | ||
expect(remove.args[0][2].id).to.equal(asset.id); | ||
done(); | ||
}, 0); | ||
}); | ||
|
||
app.assets.add(asset); | ||
app.assets.remove(asset); | ||
}); | ||
|
||
}); |
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
This file was deleted.
Oops, something went wrong.