Browse Source

test(unit): add some basic tests for Lightning class

renovate/lint-staged-8.x
Tom Kirkpatrick 6 years ago
parent
commit
602d03411a
No known key found for this signature in database GPG Key ID: 72203A8EC5967EA8
  1. 4
      app/lib/lnd/lightning.js
  2. 53
      test/unit/lnd/lightning.spec.js

4
app/lib/lnd/lightning.js

@ -89,7 +89,9 @@ class Lightning {
*/ */
disconnect() { disconnect() {
this.unsubscribe() this.unsubscribe()
this.lnd.close() if (this.lnd) {
this.lnd.close()
}
} }
/** /**

53
test/unit/lnd/lightning.spec.js

@ -0,0 +1,53 @@
import { BrowserWindow } from 'electron'
import Lightning from 'lib/lnd/lightning'
jest.mock('electron-store')
jest.mock('lib/lnd/subscribe/transactions')
jest.mock('lib/lnd/subscribe/invoices')
jest.mock('lib/lnd/subscribe/channelgraph')
describe('Lightning', function() {
describe('Constructor', () => {
beforeAll(() => (this.lightning = new Lightning()))
describe('initial values', () => {
it('should set the "mainWindow" property to null', () => {
expect(this.lightning.mainWindow).toBeNull()
})
it('should set the "lnd" property to null', () => {
expect(this.lightning.lnd).toBeNull()
})
it('should initialise the "subscriptions" object with null values', () => {
expect(this.lightning.subscriptions).toMatchObject({
channelGraph: null,
invoices: null,
transactions: null
})
})
})
})
describe('subscribe()', () => {
beforeAll(() => {
this.window = new BrowserWindow({})
this.lightning = new Lightning()
this.lightning.subscribe(this.window)
})
it('should assign the window to the "mainWindow" property', () => {
expect(this.lightning.mainWindow).toBe(this.window)
})
})
describe('unsubscribe()', () => {
beforeAll(() => {
this.lightning = new Lightning()
this.lightning.mainWindow = new BrowserWindow({})
this.lightning.unsubscribe()
})
it('should unassign the "mainWindow" property', () => {
expect(this.lightning.mainWindow).toBeNull()
})
})
})
Loading…
Cancel
Save