I'm encountering an error message, despite verifying that the strings are identical:
Expected { $$state : { status : 1, value : { customerNumber : 'customerNumber', name : 'name', userId : 'buId', customerType : 'type', address : 'displayAddress' } } }
to equal { $$state : { status : 1, value : { customerNumber : 'customerNumber', name : 'name', userId : 'buId', customerType : 'type', address : 'displayAddress' } } }.
Error: Expected { $$state : { status : 1, value : { customerNumber : 'customerNumber', name : 'name', userId : 'buId', customerType : 'type', address : 'displayAddress' } } } to equal { $$state : { status : 1, value : { customerNumber : 'customerNumber', name : 'name', userId : 'buId', customerType : 'type', address : 'displayAddress' } } }.
at C:/customerServiceSpec.js:70
The only discrepancy I can identify is a period at the end, though I suspect Jasmine adds it in the response. Here's my testing code snippet:
describe('CustomerService', () => {
var mockUserSession: any = {};
var testService any = {};
var $q: ng.IQService;
var createCustomerDetailsService;
var customerDetailsService;
var createResolvedPromise;
var createRejectedPromise;
var resolvePromises;
var testResponse = {
customers: {
displayCustomerNumber: 'customerNumber',
name: 'name',
id: 'id',
type: 'type',
displayAddress: 'displayAddress'
}
};
var serviceResponse={
$$state: {
status: 1,
value: {
customerNumber: 'customerNumber',
name: 'name',
id: 'id',
customerType: 'type',
address:'displayAddress'
}
}
};
var rootScope;
beforeEach(() => {
module('app.customer');
inject(( _$q_, $injector) => {
this.$q = _$q_;
rootScope = $injector.get('$rootScope');
createResolvedPromise = (result) => {
return () => {
return this.$q.when(result);
};
};
resolvePromises = () => {
rootScope.$digest();
};
createCustomerDetailsService = () => {
return new app.customer.CustomerService(
testService);
};
});
});
it('WILL search by customer ID and return a customers details', () => {
var searchResponsePromise;
testService.getCustomerDetails = jasmine.createSpy("getCustomerDetails").and.callFake(createResolvedPromise(testResponse));
customerDetailsService = createCustomerDetailsService();
searchResponsePromise = customerDetailsService.getCustomerDetails('12345678');
resolvePromises();
expect(searchResponsePromise).toEqual(serviceResponse);
});
});
Below is the relevant excerpt from my service:
public getCustomerDetails(customerID:string): ng.IPromise<ICustomerDetails> {
return this.testService.getCustomerDetails(customerID).then((customerResponse:ICustomerResult) => {
var customer = customerResponse.customers;
var customerDetailsResult:ICustomerDetails = {
customerNumber: customer.displayCustomerNumber,
name: customer.name,
userId: customer.buId,
customerType: customer.type,
address: customer.displayAddress
};
return customerDetailsResult;
});
}
Your assistance is greatly appreciated.