-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
835a4fa
commit 72aac4a
Showing
2 changed files
with
55 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
//------------------------------------------------------------------------------------------------------- | ||
// Copyright (C) Microsoft. All rights reserved. | ||
// Copyright (c) ChakraCore Project Contributors. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information. | ||
//------------------------------------------------------------------------------------------------------- | ||
|
||
// @ts-check | ||
/// <reference path="../UnitTestFramework/UnitTestFramework.js" /> | ||
|
||
WScript.LoadScriptFile("..\\UnitTestFramework\\UnitTestFramework.js"); | ||
|
||
const createObj = () => ({ "null": null, "undefined": undefined, something: 42 }); | ||
|
||
const tests = [ | ||
{ | ||
name: "`delete` should successfully delete from opt-chain", | ||
body() { | ||
const obj = createObj(); | ||
|
||
assert.strictEqual(null, obj?.null); | ||
assert.isTrue(delete obj?.null); | ||
assert.strictEqual(undefined, obj?.null); | ||
|
||
assert.strictEqual(undefined, obj?.undefined); | ||
assert.isTrue(delete obj?.undefined); | ||
assert.strictEqual(undefined, obj?.undefined); | ||
|
||
assert.strictEqual(42, obj?.something); | ||
assert.isTrue(delete obj?.something); | ||
assert.strictEqual(undefined, obj?.something); | ||
} | ||
}, | ||
{ | ||
name: "`delete` should return `true` if opt-chain short-circuits", | ||
body() { | ||
const obj = createObj(); | ||
|
||
assert.strictEqual(undefined, obj.doesNotExist); | ||
assert.strictEqual(undefined, obj.doesNotExist?.something); | ||
assert.isTrue(delete obj.doesNotExist?.something); | ||
assert.strictEqual(undefined, obj.doesNotExist?.something); | ||
|
||
assert.strictEqual(undefined, obj?.doesNotExist); | ||
assert.strictEqual(undefined, obj?.doesNotExist?.something); | ||
assert.isTrue(delete obj?.doesNotExist?.something); | ||
assert.strictEqual(undefined, obj?.doesNotExist?.something); | ||
} | ||
} | ||
]; | ||
|
||
testRunner.runTests(tests, { verbose: WScript.Arguments[0] != "summary" }); |
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