Skip to content

Commit 261e0b2

Browse files
committed
Platform.identify fails if no match for platform and no default
Fix adds check if default option is present. It runs default function if provided or returns undefined.
1 parent a014d1f commit 261e0b2

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

browser/services/platform.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ class Platform {
55
try {
66
return map[Platform.OS]();
77
} catch (error) {
8-
return map['default']();
8+
let defaultCallback = map['default'];
9+
return defaultCallback ? defaultCallback() : undefined;
910
}
1011
}
1112

test/unit/services/platform-test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ describe('Platform', function(){
2424
linux: ()=>'linux',
2525
default: ()=>'bummer'
2626
};
27+
let noDefaultData = {
28+
darwin: ()=>'darwin',
29+
win32: ()=>'win32',
30+
linux: ()=>'linux'
31+
};
2732

2833
it('returns value of opject\'s property named the same as current platform', function(){
2934
sandbox.stub(Platform,'getOS').returns('win32');
@@ -39,6 +44,11 @@ describe('Platform', function(){
3944
expect(Platform.identify(data)).to.be.equal('bummer');
4045
});
4146

47+
it('returns undefined if there no propyrty with current platform name and no default provided', function(){
48+
sandbox.stub(Platform,'getOS').returns('ps/2');
49+
expect(Platform.identify(noDefaultData)).to.be.equal(undefined);
50+
});
51+
4252
});
4353

4454
describe('PATH', function(){

0 commit comments

Comments
 (0)