-
-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2123 from satanTime/issues/1168
fix(core): better error messages #1168
- Loading branch information
Showing
18 changed files
with
337 additions
and
24 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
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,7 @@ | ||
import funcGetName from './func.get-name'; | ||
|
||
describe('func.get-name', () => { | ||
it('detects unknown', () => { | ||
expect(funcGetName(false)).toEqual('unknown'); | ||
}); | ||
}); |
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,16 @@ | ||
export default (value: any): string => { | ||
if (typeof value === 'function' && value.name) { | ||
return value.name; | ||
} | ||
if (typeof value === 'function') { | ||
return 'arrow-function'; | ||
} | ||
if (typeof value === 'object' && value && value.ngMetadataName === 'InjectionToken') { | ||
return value._desc; | ||
} | ||
if (typeof value === 'object' && value && typeof value.constructor === 'function') { | ||
return value.constructor.name; | ||
} | ||
|
||
return 'unknown'; | ||
}; |
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 |
---|---|---|
@@ -1,5 +1,48 @@ | ||
import funcGetName from './func.get-name'; | ||
import { isNgDef } from './func.is-ng-def'; | ||
|
||
export default (value: any, funcName: string) => { | ||
if (value === undefined || value === null) { | ||
throw new Error(`An empty parameter has been passed into ${funcName}. Please check that its import is correct.`); | ||
} | ||
|
||
if (funcName === 'MockPipe' && isNgDef(value, 'p')) { | ||
return; | ||
} | ||
if (funcName === 'MockDirective' && isNgDef(value, 'd')) { | ||
return; | ||
} | ||
if (funcName === 'MockComponent' && isNgDef(value, 'c')) { | ||
return; | ||
} | ||
if (funcName === 'MockModule' && isNgDef(value, 'm')) { | ||
return; | ||
} | ||
|
||
const type = isNgDef(value, 'p') | ||
? 'pipe' | ||
: isNgDef(value, 'd') | ||
? 'directive' | ||
: isNgDef(value, 'c') | ||
? 'component' | ||
: isNgDef(value, 'm') | ||
? 'module' | ||
: isNgDef(value, 'i') | ||
? 'service' | ||
: isNgDef(value, 't') | ||
? 'token' | ||
: ''; | ||
|
||
if (type && funcName === 'MockPipe') { | ||
throw new Error(`${funcName} accepts pipes, whereas ${funcGetName(value)} is a ${type}.`); | ||
} | ||
if (type && funcName === 'MockDirective') { | ||
throw new Error(`${funcName} accepts directives, whereas ${funcGetName(value)} is a ${type}.`); | ||
} | ||
if (type && funcName === 'MockComponent') { | ||
throw new Error(`${funcName} accepts components, whereas ${funcGetName(value)} is a ${type}.`); | ||
} | ||
if (type && funcName === 'MockModule') { | ||
throw new Error(`${funcName} accepts modules, whereas ${funcGetName(value)} is a ${type}.`); | ||
} | ||
}; |
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
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
4 changes: 3 additions & 1 deletion
4
libs/ng-mocks/src/lib/mock-service/helper.create-mock-from-prototype.ts
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
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
Oops, something went wrong.