Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(vue): Check if SDK is initialized before app is mounted
- Loading branch information
Showing
4 changed files
with
196 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import * as Sentry from './../../src'; | ||
import { createApp } from 'vue'; | ||
|
||
describe('Sentry.init', () => { | ||
let _consoleError: any; | ||
let errors: string[] = []; | ||
|
||
beforeEach(() => { | ||
errors = []; | ||
_consoleError = console.error; | ||
console.error = jest.fn((error: string) => { | ||
errors.push(error); | ||
}); | ||
}); | ||
|
||
afterEach(() => { | ||
console.error = _consoleError; | ||
}); | ||
|
||
it('does not warn when correctly mounted', () => { | ||
const el = document.createElement('div'); | ||
const app = createApp({ | ||
template: '<div>hello</div>', | ||
}); | ||
|
||
Sentry.init({ | ||
app, | ||
defaultIntegrations: false, | ||
}); | ||
|
||
app.mount(el); | ||
|
||
expect(errors).toEqual([]); | ||
}); | ||
|
||
it('warns when mounting before SDK init', () => { | ||
const el = document.createElement('div'); | ||
const app = createApp({ | ||
template: '<div>hello</div>', | ||
}); | ||
|
||
app.mount(el); | ||
|
||
Sentry.init({ | ||
app, | ||
defaultIntegrations: false, | ||
}); | ||
|
||
expect(errors).toEqual([ | ||
'[@sentry/vue]: Misconfigured SDK: Vue app is already mounted. Make sure to call `app.mount()` after `Sentry.init()`.', | ||
]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters