Skip to content

Commit bb602d2

Browse files
committed
Actualized a tests for the promises
1 parent 27ff7de commit bb602d2

File tree

4 files changed

+48
-20
lines changed

4 files changed

+48
-20
lines changed

test/JavaScriptEngineSwitcher.Tests/Es2015TestsBase.cs

+14-20
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
using System;
2-
using System.Text;
3-
4-
using Xunit;
1+
using Xunit;
52

63
namespace JavaScriptEngineSwitcher.Tests
74
{
@@ -13,39 +10,36 @@ public abstract class Es2015TestsBase : TestsBase
1310
public virtual void ExecutionOfPromisesIsCorrect()
1411
{
1512
// Arrange
16-
var stringBuilder = new StringBuilder();
17-
const string input = @"var successfulWork = new Promise(function(resolve, reject) {
18-
resolve(""Success!"");
19-
});
20-
21-
var unsuccessfulWork = new Promise(function (resolve, reject) {
22-
reject(""Fail!"");
23-
});
13+
const string input = @"var output = '',
14+
successfulWork = new Promise(function(resolve, reject) {
15+
resolve('Success!');
16+
}),
17+
unsuccessfulWork = new Promise(function (resolve, reject) {
18+
reject('Fail!');
19+
})
20+
;
2421
2522
function resolveCallback(result) {
26-
stringBuilder.AppendLine('Resolved: ' + result);
23+
output += 'Resolved: ' + result + '\n';
2724
}
2825
2926
function rejectCallback(reason) {
30-
stringBuilder.AppendLine('Rejected: ' + reason);
27+
output += 'Rejected: ' + reason + '\n';
3128
}
3229
3330
successfulWork.then(resolveCallback, rejectCallback);
3431
unsuccessfulWork.then(resolveCallback, rejectCallback);";
35-
string targetOutput = "Resolved: Success!" + Environment.NewLine +
36-
"Rejected: Fail!" + Environment.NewLine
32+
string targetOutput = "Resolved: Success!\n" +
33+
"Rejected: Fail!\n"
3734
;
3835

3936
// Act
4037
string output;
4138

4239
using (var jsEngine = CreateJsEngine())
4340
{
44-
jsEngine.EmbedHostObject("stringBuilder", stringBuilder);
4541
jsEngine.Execute(input);
46-
47-
output = stringBuilder.ToString();
48-
stringBuilder.Clear();
42+
output = jsEngine.GetVariableValue<string>("output");
4943
}
5044

5145
// Assert
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#if !NET452
2+
namespace JavaScriptEngineSwitcher.Tests.Jint
3+
{
4+
public class Es2015Tests : Es2015TestsBase
5+
{
6+
protected override string EngineName
7+
{
8+
get { return "JintJsEngine"; }
9+
}
10+
}
11+
}
12+
#endif
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace JavaScriptEngineSwitcher.Tests.Jurassic
2+
{
3+
public class Es2015Tests : Es2015TestsBase
4+
{
5+
protected override string EngineName
6+
{
7+
get { return "JurassicJsEngine"; }
8+
}
9+
}
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#if !NET452
2+
namespace JavaScriptEngineSwitcher.Tests.Node
3+
{
4+
public class Es2015Tests : Es2015TestsBase
5+
{
6+
protected override string EngineName
7+
{
8+
get { return "NodeJsEngine"; }
9+
}
10+
}
11+
}
12+
#endif

0 commit comments

Comments
 (0)