Yes, we often uses fixtures for tests, especially tests for widgets that use a model internally.
In a recent application, we created some high-level model tests that allow us to write a single test that tests against fixtures AND the service layer.
Here's the code:
- var adminLoggedIn,
- modules = {},
- currentModule;
- return {
- fixtureAndServiceModule: function(name, config){
- currentModule = { tests: [], config: config};
- modules[name] = currentModule;
- },
- fixtureAndServiceTest: function(name, fn){
- currentModule.tests.push({
- name: name,
- fn: fn
- })
- },
- createModulesAndTests: function(fixturesOnly){
- if(fixturesOnly !== true){
- for(var name in modules){
- var mod = modules[name]
- module(name+" services",mod.config);
- can.each(mod.tests, function(testData){
- test(testData.name, function(){
- fixture.on = false;
- testData.fn()
- })
- })
- }
- }
- for(var name in modules){
- var mod = modules[name]
- module(name+" fixtures",mod.config);
- can.each(mod.tests, function(testData){
- test(testData.name, testData.fn)
- })
- }
- },
What this code allows is a test like:
- helpers.fixtureAndServiceModule('safety/models/customer.js',{
- setup: function(){
- fixture.on = true
- fixtures.customerStore.reset()
- }
- })
- helpers.fixtureAndServiceTest("create and destroy",function(){
- stop()
- new Customer({
- name: "TEST-Abbott"
- }).save(function(customer){ ... }})
Basically, fixtureAndServiceTest creates a test that QUnit will run twice, once with fixtures on, another with them off.
I'm not sure if that helps answer your question however.