chore: finish replacing assert with expect in tests (#18215)
* spec: replace assert with expect in api-browser-view-spec.js * spec: replace assert with expect in api-touch-bar-spec.js * spec: replace assert with expect in api-web-frame-spec.js * spec: replace assert with expect in api-web-contents-view-spec.js * spec: replace assert with expect in security-warnings-spec.js * spec: replace assert with expect in api-menu-item-spec.js * spec: replace assert with expect in api-web-request-spec.js * spec: replace assert with expect in api-remote-spec.js * spec: replace assert with expect in api-session-spec.js * spec: replace assert with expect in api-system-preferences-spec.js * spec: replace assert with expect in api-browser-window-spec.js * spec: replace assert with expect in webview-spec.js * spec: replace assert with expect in api-net-spec.js * spec: replace assert with expect in api-protocol-spec.js * spec: replace assert with expect api-web-contents-spec.js * spec: replace assert with expect in api-shell-spec.js * spec: replace assert with expect in modules-spec.js * spec: replace assert with expect in chromium-spec.js * spec: replace assert with expect in api-crash-reporter-spec.js * spec: replace assert with expect in asar-spec.js * spec: rename assert-helpers to expect-helpers * address PR feedback
This commit is contained in:
parent
dbb8617214
commit
5a7b56b042
22 changed files with 1546 additions and 1591 deletions
|
@ -1,9 +1,14 @@
|
|||
const assert = require('assert')
|
||||
const chai = require('chai')
|
||||
const dirtyChai = require('dirty-chai')
|
||||
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const os = require('os')
|
||||
const { shell } = require('electron')
|
||||
|
||||
const { expect } = chai
|
||||
chai.use(dirtyChai)
|
||||
|
||||
describe('shell module', () => {
|
||||
const fixtures = path.resolve(__dirname, 'fixtures')
|
||||
const shortcutOptions = {
|
||||
|
@ -54,14 +59,14 @@ describe('shell module', () => {
|
|||
})
|
||||
|
||||
it('throws when failed', () => {
|
||||
assert.throws(() => {
|
||||
expect(() => {
|
||||
shell.readShortcutLink('not-exist')
|
||||
}, /Failed to read shortcut link/)
|
||||
}).to.throw('Failed to read shortcut link')
|
||||
})
|
||||
|
||||
it('reads all properties of a shortcut', () => {
|
||||
const shortcut = shell.readShortcutLink(path.join(fixtures, 'assets', 'shortcut.lnk'))
|
||||
assert.deepStrictEqual(shortcut, shortcutOptions)
|
||||
expect(shortcut).to.deep.equal(shortcutOptions)
|
||||
})
|
||||
})
|
||||
|
||||
|
@ -77,28 +82,28 @@ describe('shell module', () => {
|
|||
})
|
||||
|
||||
it('writes the shortcut', () => {
|
||||
assert.strictEqual(shell.writeShortcutLink(tmpShortcut, { target: 'C:\\' }), true)
|
||||
assert.strictEqual(fs.existsSync(tmpShortcut), true)
|
||||
expect(shell.writeShortcutLink(tmpShortcut, { target: 'C:\\' })).to.be.true()
|
||||
expect(fs.existsSync(tmpShortcut)).to.be.true()
|
||||
})
|
||||
|
||||
it('correctly sets the fields', () => {
|
||||
assert.strictEqual(shell.writeShortcutLink(tmpShortcut, shortcutOptions), true)
|
||||
assert.deepStrictEqual(shell.readShortcutLink(tmpShortcut), shortcutOptions)
|
||||
expect(shell.writeShortcutLink(tmpShortcut, shortcutOptions)).to.be.true()
|
||||
expect(shell.readShortcutLink(tmpShortcut)).to.deep.equal(shortcutOptions)
|
||||
})
|
||||
|
||||
it('updates the shortcut', () => {
|
||||
assert.strictEqual(shell.writeShortcutLink(tmpShortcut, 'update', shortcutOptions), false)
|
||||
assert.strictEqual(shell.writeShortcutLink(tmpShortcut, 'create', shortcutOptions), true)
|
||||
assert.deepStrictEqual(shell.readShortcutLink(tmpShortcut), shortcutOptions)
|
||||
expect(shell.writeShortcutLink(tmpShortcut, 'update', shortcutOptions)).to.be.false()
|
||||
expect(shell.writeShortcutLink(tmpShortcut, 'create', shortcutOptions)).to.be.true()
|
||||
expect(shell.readShortcutLink(tmpShortcut)).to.deep.equal(shortcutOptions)
|
||||
const change = { target: 'D:\\' }
|
||||
assert.strictEqual(shell.writeShortcutLink(tmpShortcut, 'update', change), true)
|
||||
assert.deepStrictEqual(shell.readShortcutLink(tmpShortcut), Object.assign(shortcutOptions, change))
|
||||
expect(shell.writeShortcutLink(tmpShortcut, 'update', change)).to.be.true()
|
||||
expect(shell.readShortcutLink(tmpShortcut)).to.deep.equal(Object.assign(shortcutOptions, change))
|
||||
})
|
||||
|
||||
it('replaces the shortcut', () => {
|
||||
assert.strictEqual(shell.writeShortcutLink(tmpShortcut, 'replace', shortcutOptions), false)
|
||||
assert.strictEqual(shell.writeShortcutLink(tmpShortcut, 'create', shortcutOptions), true)
|
||||
assert.deepStrictEqual(shell.readShortcutLink(tmpShortcut), shortcutOptions)
|
||||
expect(shell.writeShortcutLink(tmpShortcut, 'replace', shortcutOptions)).to.be.false()
|
||||
expect(shell.writeShortcutLink(tmpShortcut, 'create', shortcutOptions)).to.be.true()
|
||||
expect(shell.readShortcutLink(tmpShortcut)).to.deep.equal(shortcutOptions)
|
||||
const change = {
|
||||
target: 'D:\\',
|
||||
description: 'description2',
|
||||
|
@ -108,8 +113,8 @@ describe('shell module', () => {
|
|||
icon: 'icon2',
|
||||
iconIndex: 2
|
||||
}
|
||||
assert.strictEqual(shell.writeShortcutLink(tmpShortcut, 'replace', change), true)
|
||||
assert.deepStrictEqual(shell.readShortcutLink(tmpShortcut), change)
|
||||
expect(shell.writeShortcutLink(tmpShortcut, 'replace', change)).to.be.true()
|
||||
expect(shell.readShortcutLink(tmpShortcut)).to.deep.equal(change)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue