-
Notifications
You must be signed in to change notification settings - Fork 344
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add warn * test: add test for warn
- Loading branch information
Showing
5 changed files
with
47 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { getCurrentInstance } from '../runtimeContext' | ||
import { warn as vueWarn } from '../utils' | ||
|
||
/** | ||
* Displays a warning message (using console.error) with a stack trace if the | ||
* function is called inside of active component. | ||
* | ||
* @param message warning message to be displayed | ||
*/ | ||
export function warn(message: string) { | ||
vueWarn(message, getCurrentInstance()) | ||
} |
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,32 @@ | ||
const Vue = require('vue/dist/vue.common.js') | ||
const { warn: apiWarn } = require('../../src') | ||
|
||
describe('api/warn', () => { | ||
beforeEach(() => { | ||
warn = jest.spyOn(global.console, 'error').mockImplementation(() => null) | ||
}) | ||
afterEach(() => { | ||
warn.mockRestore() | ||
}) | ||
|
||
it('can be called inside a component', () => { | ||
new Vue({ | ||
setup() { | ||
apiWarn('warned') | ||
}, | ||
template: `<div></div>`, | ||
}).$mount() | ||
|
||
expect(warn).toHaveBeenCalledTimes(1) | ||
expect(warn.mock.calls[0][0]).toMatch( | ||
/\[Vue warn\]: warned[\s\S]*\(found in <Root>\)/ | ||
) | ||
}) | ||
|
||
it('can be called outside a component', () => { | ||
apiWarn('warned') | ||
|
||
expect(warn).toHaveBeenCalledTimes(1) | ||
expect(warn).toHaveBeenCalledWith('[Vue warn]: warned') | ||
}) | ||
}) |