本文整理匯總了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
//.........這裏部分代碼省略.........