Cum se mock-uiesc datele?

  • data:

myDate: new Date()

  • un Url

myUrl: “http://myTestURL”

  • un boolean

myBoolean: true

myBoolean: false

  • un string:

myString: “” , daca vrem sa fie gol sau

myString:”test”

  • un array:

myArray: []

  • un obiect:

myObject: {}

  • un array de obiecte:

myArrayOfObjects: [{},{},{}]

  • un observable:

myObservable: ko.observable()

myObservable: ko.observable(true)

myObservable: ko.observable(false)

myObservable: ko.observable(“myString”)

  • un observableArray:

myObservable: ko.observableArray()

  • o functie care nu retuneaza nimic:

myFunction: function () { }

  • o functie care retuneaza un obiect:

myFunction: function () { return {}; }

  • o functie care retuneaza un promise:

myFunction: function() { return $.Deferred().promise(); }

  • un promise:

putPromise: function() {
return $.Deferred().resolve(‘Test’, ‘success’, { status: 200 }).promise();
}

myPromise: $.Deferred().resolve({Items: [], Links: []})

myPromise: function (param) {
var dfr = $.Deferred();
dfr.resolve(param);
return dfr.promise();
}

myPromise: function (param) {
var dfr = $.Deferred();
dfr.resolve(null, [[]]);
return dfr.promise();
}

  • un event

myEvent: ko.event()

  • un spy:

myFunction: jasmine.createSpy()

myFunction: jasmine.createSpy(‘myFunction’)

myFunction: jasmine.createSpy(‘myFunction’).and.callFake(function () {
return $.Deferred().resolve({}, 200, {status: ‘OK’}).promise();
})

myObservable: jasmine.createSpy(‘myObservableSpy’,myObservable).and.callThroug()

  • un ViewModel

myViewModel= new myViewModel()

myViewModel= new myViewModel(param)

  • fake server

myFakeserver: sinon.fakeServer.create();

myFakeServer.respondWith(“GET”, myUrl, JSON.stringify(response));

  • functie ce returneaza un promise

sinon.stub().returns($.Deferred().resolve([]).promise())

sinon.spy(function () { var dfr = $.Deferred(); dfr.resolve(); return dfr.promise(); });

jasmine.createSpy().and.callFake(function() {
return smth;
})

myMethod: sinon.stub().returns(cachedProductListingMock)

myMethod: sinon.stub().returns({})

sinon.spy()

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s