如何将一个功能转换为其他功能进行文件测试?

时间:2019-01-19 13:47:34

标签: javascript firebase-realtime-database redux jestjs redux-saga

在我的传奇故事中,我有以下代码:

export function* removeProfile(auth, database){
try{  
    const url = `/users/${action.user.uid}` 

    const {ref} = database
    const {remove} = database.ref()
    const result = yield call([database, ref], url)
    yield call([result, remove])

    const deleteFunction = () => action.user.delete()
    yield call([action.user, deleteFunction])

    //yield action.user.delete() && database.ref(url).remove()
    yield put(ActionCreator.removeProfileSuccess()) 
    yield destroyAuth(auth)  
}catch({message}){
     yield put(ActionCreator.removeProfileFailure(message))      
}     
}

在我的睾丸中,我有另一个代码:

describe('should test removeProfile', () => {

const databaseMock = {
    ref: jest.fn()
}
const {ref} = databaseMock
const remove = databaseMock.ref() // i need to do something like this, for get remove function, but i don't need if this is correct

const url = undefined

const it = sagaHelper(removeProfile(authMock, databaseMock, action))

it('should call apis ref and remove from database', result => {
    let newResult = {}
    expect(result).toEqual(newResult = call([databaseMock, ref], url))
    expect(newResult).toEqual(call([newResult, remove]))
})
})

我的疑问是:在测试代码中,我需要获取remove函数,该函数位于其他函数下(database.ref())。我怎样才能做到这一点。 expect(result).toEqual(newResult = call([databaseMock, ref], url)) expect(newResult).toEqual(call([newResult, remove]))是正确的吗?

0 个答案:

没有答案
相关问题