本文整理汇总了TypeScript中deep-freeze-node类的典型用法代码示例。如果您正苦于以下问题:TypeScript deep-freeze-node类的具体用法?TypeScript deep-freeze-node怎么用?TypeScript deep-freeze-node使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了deep-freeze-node类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: deepFreeze
import * as deepFreeze from 'deep-freeze-node'
import * as shieldsPanelState from '../../../brave_extension/extension/brave_extension/state/shieldsPanelState'
import { State } from '../../../brave_extension/extension/brave_extension/types/state/shieldsPannelState'
const state: State = deepFreeze({
currentWindowId: 1,
tabs: {
2: {
id: 2,
ads: 'block',
trackers: 'block',
httpUpgradableResources: 'block',
javascript: 'block',
fingerprinting: 'block',
cookies: 'block'
},
3: {
id: 3
},
4: {
id: 4
}
},
windows: {
1: 2,
2: 3
}
})
describe('shieldsPanelState test', () => {
describe('getActiveTabId', () => {
it('Obtains the active tab ID based on the current window', () => {
示例2: describe
describe('WINDOW_FOCUS_CHANGED', () => {
const windowId = 1
const tabId = 2
let updateFocusedWindowSpy: jest.SpyInstance
let requestShieldPanelDataSpy: jest.SpyInstance
const state = deepFreeze({
...initialState.shieldsPanel,
windows: {
1: tabId
},
tabs: {
[tabId]: { url: 'https://brave.com' }
}
})
beforeEach(() => {
updateFocusedWindowSpy = jest.spyOn(shieldsPanelState, 'updateFocusedWindow')
requestShieldPanelDataSpy = jest.spyOn(shieldsAPI, 'requestShieldPanelData')
})
afterEach(() => {
updateFocusedWindowSpy.mockRestore()
requestShieldPanelDataSpy.mockRestore()
})
it('calls shieldsPanelState.updateFocusedWindow', () => {
shieldsPanelReducer(state, { type: windowTypes.WINDOW_FOCUS_CHANGED, windowId: windowId })
expect(updateFocusedWindowSpy).toBeCalledTimes(1)
expect(updateFocusedWindowSpy.mock.calls[0][1]).toBe(windowId)
})
it('calls shieldsPanelState.requestShieldPanelDataSpy ', () => {
shieldsPanelReducer(state, { type: windowTypes.WINDOW_FOCUS_CHANGED, windowId: windowId })
expect(requestShieldPanelDataSpy).toBeCalledWith(tabId)
})
})
示例3: beforeEach
beforeEach(() => {
updateFocusedWindowSpy = jest.spyOn(shieldsPanelState, 'updateFocusedWindow')
requestShieldPanelDataSpy = jest.spyOn(shieldsAPI, 'requestShieldPanelData')
const state = deepFreeze({
...initialState.shieldsPanel,
windows: {
1: tabId
},
tabs: {
[tabId]: { url: 'https://brave.com' }
}
})
shieldsPanelReducer(state, {
type: windowTypes.WINDOW_FOCUS_CHANGED,
windowId: windowId
})
})
示例4: it
it('increases different tab counts separately', () => {
let nextState = deepFreeze(shieldsPanelReducer(state, {
type: types.RESOURCE_BLOCKED,
details: {
blockType: 'ads',
tabId: 2,
subresource: 'https://test.brave.com'
}
}))
expect(nextState).toEqual({
currentWindowId: 1,
tabs: {
2: {
adsBlocked: 1,
trackersBlocked: 0,
httpsRedirected: 0,
javascriptBlocked: 0,
fingerprintingBlocked: 0,
origin: 'https://brave.com',
hostname: 'brave.com',
controlsOpen: true,
braveShields: 'allow',
httpUpgradableResources: 'block',
id: 2,
javascript: 'block',
trackers: 'block',
ads: 'block',
fingerprinting: 'block',
cookies: 'block',
noScriptInfo: {},
trackersBlockedResources: [],
adsBlockedResources: [
'https://test.brave.com'
],
fingerprintingBlockedResources: [],
httpsRedirectedResources: [],
javascriptBlockedResources: []
}
},
windows: {
1: 2
}
})
nextState = shieldsPanelReducer(nextState, {
type: types.RESOURCE_BLOCKED,
details: {
blockType: 'ads',
tabId: 3,
subresource: 'https://test.brave.com'
}
})
expect(nextState).toEqual({
currentWindowId: 1,
tabs: {
2: {
origin: 'https://brave.com',
hostname: 'brave.com',
adsBlocked: 1,
trackersBlocked: 0,
httpsRedirected: 0,
javascriptBlocked: 0,
fingerprintingBlocked: 0,
controlsOpen: true,
braveShields: 'allow',
httpUpgradableResources: 'block',
id: 2,
javascript: 'block',
trackers: 'block',
ads: 'block',
fingerprinting: 'block',
cookies: 'block',
noScriptInfo: {},
trackersBlockedResources: [],
adsBlockedResources: [ 'https://test.brave.com' ],
fingerprintingBlockedResources: [],
httpsRedirectedResources: [],
javascriptBlockedResources: []
},
3: {
adsBlocked: 1,
trackersBlocked: 0,
httpsRedirected: 0,
javascriptBlocked: 0,
fingerprintingBlocked: 0,
noScriptInfo: {},
trackersBlockedResources: [],
adsBlockedResources: [ 'https://test.brave.com' ],
fingerprintingBlockedResources: [],
httpsRedirectedResources: [],
javascriptBlockedResources: []
}
},
windows: {
1: 2
}
})
})
示例5: ChromeEvent
},
extension: {
inIncognitoContext: new ChromeEvent()
},
topSites: {
get: function () {
return
}
},
bookmarks: {
search: function () {
return
}
}
}
}
export const initialState = deepFreeze({
cosmeticFilter: {
currentWindowId: -1,
tabs: {},
windows: {}
},
runtime: {},
shieldsPanel: {
currentWindowId: -1,
tabs: {},
windows: {}
}
})
示例6: it
describe('cosmeticFilterReducer', () => {
it('should handle initial state', () => {
expect(shieldsPanelReducer(undefined, actions.blockAdsTrackers('allow')))
.toEqual(initialState.cosmeticFilter)
})
describe('ON_COMMITTED', () => {
const tabId = 1
let spy: jest.SpyInstance
let resetNoScriptInfoSpy: jest.SpyInstance
let resetBlockingResourcesSpy: jest.SpyInstance
beforeEach(() => {
spy = jest.spyOn(shieldsPanelState, 'resetBlockingStats')
resetNoScriptInfoSpy = jest.spyOn(shieldsPanelState, 'resetNoScriptInfo')
resetBlockingResourcesSpy = jest.spyOn(shieldsPanelState, 'resetBlockingResources')
})
afterEach(() => {
spy.mockRestore()
resetNoScriptInfoSpy.mockRestore()
resetBlockingResourcesSpy.mockRestore()
})
it('calls resetBlockingStats when isMainFrame is true', () => {
shieldsPanelReducer(initialState.shieldsPanel, {
type: webNavigationTypes.ON_COMMITTED,
tabId: tabId,
url: 'https://www.brave.com',
isMainFrame: true
})
expect(spy).toBeCalledTimes(1)
expect(spy.mock.calls[0][1]).toBe(tabId)
})
it('does not call resetBlockingStats when isMainFrame is false', () => {
shieldsPanelReducer(initialState.shieldsPanel, {
type: webNavigationTypes.ON_COMMITTED,
tabId: tabId,
url: 'https://www.brave.com',
isMainFrame: false
})
expect(spy).not.toBeCalled()
})
it('calls resetNoScriptInfo when isMainFrame is true', () => {
shieldsPanelReducer(initialState.shieldsPanel, {
type: webNavigationTypes.ON_COMMITTED,
tabId: tabId,
url: 'https://www.brave.com',
isMainFrame: true
})
expect(resetNoScriptInfoSpy).toBeCalledTimes(1)
expect(resetNoScriptInfoSpy.mock.calls[0][1]).toBe(tabId)
expect(resetNoScriptInfoSpy.mock.calls[0][2]).toBe('https://www.brave.com')
})
it('does not call resetNoScriptInfo when isMainFrame is false', () => {
shieldsPanelReducer(initialState.shieldsPanel, {
type: webNavigationTypes.ON_COMMITTED,
tabId: tabId,
url: 'https://www.brave.com',
isMainFrame: false
})
expect(resetNoScriptInfoSpy).not.toBeCalled()
})
it('calls resetBlockingResources when isMainFrame is true', () => {
shieldsPanelReducer(initialState.shieldsPanel, {
type: webNavigationTypes.ON_COMMITTED,
tabId: tabId,
url: 'https://www.brave.com',
isMainFrame: true
})
expect(spy).toBeCalledTimes(1)
expect(spy.mock.calls[0][1]).toBe(tabId)
})
it('does not call resetBlockingResources when isMainFrame is false', () => {
shieldsPanelReducer(initialState.shieldsPanel, {
type: webNavigationTypes.ON_COMMITTED,
tabId: tabId,
url: 'https://www.brave.com',
isMainFrame: false
})
expect(spy).not.toBeCalled()
})
})
describe('WINDOW_REMOVED', () => {
const windowId = 1
let spy: jest.SpyInstance
beforeEach(() => {
spy = jest.spyOn(shieldsPanelState, 'removeWindowInfo')
})
afterEach(() => {
spy.mockRestore()
})
it('calls shieldsPanelState.removeWindowInfo', () => {
shieldsPanelReducer(initialState.shieldsPanel, {
type: windowTypes.WINDOW_REMOVED,
windowId
})
expect(spy).toBeCalledTimes(1)
expect(spy.mock.calls[0][1]).toBe(windowId)
})
})
describe('WINDOW_FOCUS_CHANGED', () => {
const windowId = 1
const tabId = 2
//.........这里部分代码省略.........