spec: convert dialog spec to expect (#13271)

This commit is contained in:
Shelley Vohr 2018-06-18 07:56:03 -07:00 коммит произвёл GitHub
Родитель 78e199b5d7
Коммит fe94bf7c1d
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
1 изменённых файлов: 45 добавлений и 45 удалений

Просмотреть файл

@ -1,112 +1,112 @@
const assert = require('assert') const {expect} = require('chai')
const {dialog} = require('electron').remote const {dialog} = require('electron').remote
describe('dialog module', () => { describe('dialog module', () => {
describe('showOpenDialog', () => { describe('showOpenDialog', () => {
it('throws errors when the options are invalid', () => { it('throws errors when the options are invalid', () => {
assert.throws(() => { expect(() => {
dialog.showOpenDialog({properties: false}) dialog.showOpenDialog({properties: false})
}, /Properties must be an array/) }).to.throw(/Properties must be an array/)
assert.throws(() => { expect(() => {
dialog.showOpenDialog({title: 300}) dialog.showOpenDialog({title: 300})
}, /Title must be a string/) }).to.throw(/Title must be a string/)
assert.throws(() => { expect(() => {
dialog.showOpenDialog({buttonLabel: []}) dialog.showOpenDialog({buttonLabel: []})
}, /Button label must be a string/) }).to.throw(/Button label must be a string/)
assert.throws(() => { expect(() => {
dialog.showOpenDialog({defaultPath: {}}) dialog.showOpenDialog({defaultPath: {}})
}, /Default path must be a string/) }).to.throw(/Default path must be a string/)
assert.throws(() => { expect(() => {
dialog.showOpenDialog({message: {}}) dialog.showOpenDialog({message: {}})
}, /Message must be a string/) }).to.throw(/Message must be a string/)
}) })
}) })
describe('showSaveDialog', () => { describe('showSaveDialog', () => {
it('throws errors when the options are invalid', () => { it('throws errors when the options are invalid', () => {
assert.throws(() => { expect(() => {
dialog.showSaveDialog({title: 300}) dialog.showSaveDialog({title: 300})
}, /Title must be a string/) }).to.throw(/Title must be a string/)
assert.throws(() => { expect(() => {
dialog.showSaveDialog({buttonLabel: []}) dialog.showSaveDialog({buttonLabel: []})
}, /Button label must be a string/) }).to.throw(/Button label must be a string/)
assert.throws(() => { expect(() => {
dialog.showSaveDialog({defaultPath: {}}) dialog.showSaveDialog({defaultPath: {}})
}, /Default path must be a string/) }).to.throw(/Default path must be a string/)
assert.throws(() => { expect(() => {
dialog.showSaveDialog({message: {}}) dialog.showSaveDialog({message: {}})
}, /Message must be a string/) }).to.throw(/Message must be a string/)
assert.throws(() => { expect(() => {
dialog.showSaveDialog({nameFieldLabel: {}}) dialog.showSaveDialog({nameFieldLabel: {}})
}, /Name field label must be a string/) }).to.throw(/Name field label must be a string/)
}) })
}) })
describe('showMessageBox', () => { describe('showMessageBox', () => {
it('throws errors when the options are invalid', () => { it('throws errors when the options are invalid', () => {
assert.throws(() => { expect(() => {
dialog.showMessageBox(undefined, {type: 'not-a-valid-type'}) dialog.showMessageBox(undefined, {type: 'not-a-valid-type'})
}, /Invalid message box type/) }).to.throw(/Invalid message box type/)
assert.throws(() => { expect(() => {
dialog.showMessageBox(null, {buttons: false}) dialog.showMessageBox(null, {buttons: false})
}, /Buttons must be an array/) }).to.throw(/Buttons must be an array/)
assert.throws(() => { expect(() => {
dialog.showMessageBox({title: 300}) dialog.showMessageBox({title: 300})
}, /Title must be a string/) }).to.throw(/Title must be a string/)
assert.throws(() => { expect(() => {
dialog.showMessageBox({message: []}) dialog.showMessageBox({message: []})
}, /Message must be a string/) }).to.throw(/Message must be a string/)
assert.throws(() => { expect(() => {
dialog.showMessageBox({detail: 3.14}) dialog.showMessageBox({detail: 3.14})
}, /Detail must be a string/) }).to.throw(/Detail must be a string/)
assert.throws(() => { expect(() => {
dialog.showMessageBox({checkboxLabel: false}) dialog.showMessageBox({checkboxLabel: false})
}, /checkboxLabel must be a string/) }).to.throw(/checkboxLabel must be a string/)
}) })
}) })
describe('showErrorBox', () => { describe('showErrorBox', () => {
it('throws errors when the options are invalid', () => { it('throws errors when the options are invalid', () => {
assert.throws(() => { expect(() => {
dialog.showErrorBox() dialog.showErrorBox()
}, /Insufficient number of arguments/) }).to.throw(/Insufficient number of arguments/)
assert.throws(() => { expect(() => {
dialog.showErrorBox(3, 'four') dialog.showErrorBox(3, 'four')
}, /Error processing argument at index 0/) }).to.throw(/Error processing argument at index 0/)
assert.throws(() => { expect(() => {
dialog.showErrorBox('three', 4) dialog.showErrorBox('three', 4)
}, /Error processing argument at index 1/) }).to.throw(/Error processing argument at index 1/)
}) })
}) })
describe('showCertificateTrustDialog', () => { describe('showCertificateTrustDialog', () => {
it('throws errors when the options are invalid', () => { it('throws errors when the options are invalid', () => {
assert.throws(() => { expect(() => {
dialog.showCertificateTrustDialog() dialog.showCertificateTrustDialog()
}, /options must be an object/) }).to.throw(/options must be an object/)
assert.throws(() => { expect(() => {
dialog.showCertificateTrustDialog({}) dialog.showCertificateTrustDialog({})
}, /certificate must be an object/) }).to.throw(/certificate must be an object/)
assert.throws(() => { expect(() => {
dialog.showCertificateTrustDialog({certificate: {}, message: false}) dialog.showCertificateTrustDialog({certificate: {}, message: false})
}, /message must be a string/) }).to.throw(/message must be a string/)
}) })
}) })
}) })