You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import{getAccessToken}from'./http-header-token';jest.mock('@utils/token/token');constTokenUtility=require('@utils/token/token');describe('[http-header-token]',function(){
let spy: jest.SpyInstance;beforeEach(()=>{spy=jest.spyOn(TokenUtility,'getAccessToken').mockReturnValue(Promise.resolve('accessToken'));});describe(`putConsentAgreement API`,function(){constapiUrl='/customer/v1/consents';constdata={consents: [{sourceType: 'ONBOARD',},],};it(`should be return undefined, source type is 'ONBOARD' and data is object`,async()=>{constresult=awaitgetAccessToken({url: apiUrl,method: 'post',
data,});expect(spy).toBeCalledTimes(0);expect(result).toBeUndefined();});it(`should be return undefined, source type is 'ONBOARD' and data is string`,function(){returnexpect(getAccessToken({url: apiUrl,method: 'post',data: JSON.stringify(data),})).resolves.toBeUndefined();});});});
Class type mocking
import{HttpConstants}from'@constants';import{i18n}from'@utils/locale';importFivuAPIfrom'@store/api/FivuAPI';import{mockWindonwLocation}from'@tests/utility';import{generateHttpCommonHeader}from'./http-gen';const{HEADER_NAMES}=HttpConstants;constXSRF_TOKEN='xsrfToken';constSTORED_LINE_USER_ID='storedLineUserId';constCONTEXT_LINE_USER_ID='contextLineUserId';constACCESS_TOKEN='accessToken';constNATIVE_INFO={...};jest.mock('@store/registry',()=>{return{getState: jest.fn(),getReducer: ()=>{return{xsrfTokenSelector: ()=>XSRF_TOKEN,userInfoSelector: ()=>STORED_USER_ID,};},};});jest.mock('@store/api/FivuAPI',()=>{return{getContext: jest.fn(),getAccessToken: ()=>ACCESS_TOKEN,finGetNativeInfo: jest.fn(),};});describe('generateHttpCommonHeader',function(){it(`should be set X_LINE_USER_ID by store , if device context is empty`,async()=>{// @ts-ignorejest.spyOn(FivuAPI,'getContext').mockReturnValue({});constresult=awaitgenerateHttpCommonHeader()();expect(result[HEADER_NAMES.X_USER_ID]).toBe(STORED_USER_ID);});it(`should be set X_LINE_USER_ID by native , if device context is not empty`,async()=>{// @ts-ignorejest.spyOn(FivuAPI,'getContext').mockReturnValue({userId: CONTEXT_USER_ID});constresult=awaitgenerateHttpCommonHeader()();expect(result[HEADER_NAMES.X_USER_ID]).toBe(CONTEXT_LINE_USER_ID);});});
The text was updated successfully, but these errors were encountered:
Date Mocking
Internal Module & promise type
Class type mocking
The text was updated successfully, but these errors were encountered: