yo @Antonio, I hope this helps you, it's a simple example
importchai,{expect}from'chai';importsinonChaifrom'sinon-chai';import*asangularfrom'angular';importotListServicefrom'ot/components/widget/listService';importotResourceServicefrom'ot/components/resourceService';chai.use(sinonChai);describe('otListService',function(){letTest;let_otListService;lethttpBackend;let_OT_LIST_ITEMS_PER_PAGE;letresponseArray=[{id:1,name:'carapuce'},{id:2,name:'salameche'},{id:3,name:'bulbizare'}];beforeEach(function(){angular.mock.module(otListService,otResourceService);inject(function(otResource,otListService,$httpBackend,OT_LIST_ITEMS_PER_PAGE){_otListService=otListService;httpBackend=$httpBackend;Test=otResource('test');_OT_LIST_ITEMS_PER_PAGE=OT_LIST_ITEMS_PER_PAGE;});});afterEach(function(){httpBackend.verifyNoOutstandingExpectation();httpBackend.verifyNoOutstandingRequest();});describe('query()',function(){it('should be able to request the resource without pagination',function(done){httpBackend.expectGET('test?orderBy=name&reverse=false').respond(JSON.stringify({models:responseArray}),{'X-Count':responseArray.length});_otListService.query(Test,null,null,null,null,null,function(data,totalItemCount){data.should.be.an.instanceof(Array);data.should.have.length(responseArray.length);expect(totalItemCount).to.be.equal(responseArray.length);done();});httpBackend.flush();});
yo @Antonio, I hope this helps you, it's a simple example
Hi!
Thanks!! very useful!
Regards!