Skip to content

Commit eecfcac

Browse files
committed
Unit test for AddScriptWithoutTransform. References #91
1 parent 0536603 commit eecfcac

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

src/React.Tests/Core/JavaScriptEngineFactoryTest.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* of patent rights can be found in the PATENTS file in the same directory.
88
*/
99

10+
using System.Collections.Generic;
1011
using System.Threading;
1112
using JavaScriptEngineSwitcher.Core;
1213
using Moq;
@@ -20,6 +21,8 @@ public class JavaScriptEngineFactoryTest
2021
private JavaScriptEngineFactory CreateFactory()
2122
{
2223
var config = new Mock<IReactSiteConfiguration>();
24+
config.Setup(x => x.ScriptsWithoutTransform).Returns(new List<string>());
25+
config.Setup(x => x.LoadReact).Returns(true);
2326
var fileSystem = new Mock<IFileSystem>();
2427
var registration = new JavaScriptEngineFactory.Registration
2528
{
@@ -81,5 +84,31 @@ public void ShouldCreateNewEngineForNewThread()
8184
Assert.AreEqual(engine1, engine3);
8285
factory.DisposeEngineForCurrentThread();
8386
}
87+
88+
[Test]
89+
public void ShouldLoadFilesThatDoNotRequireTransform()
90+
{
91+
var jsEngine = new Mock<IJsEngine>();
92+
jsEngine.Setup(x => x.Evaluate<int>("1 + 1")).Returns(2);
93+
94+
var config = new Mock<IReactSiteConfiguration>();
95+
config.Setup(x => x.ScriptsWithoutTransform).Returns(new List<string> { "First.js", "Second.js" });
96+
config.Setup(x => x.LoadReact).Returns(true);
97+
98+
var fileSystem = new Mock<IFileSystem>();
99+
fileSystem.Setup(x => x.ReadAsString(It.IsAny<string>())).Returns<string>(path => "CONTENTS_" + path);
100+
101+
var registration = new JavaScriptEngineFactory.Registration
102+
{
103+
Factory = () => jsEngine.Object,
104+
Priority = 1
105+
};
106+
var factory = new JavaScriptEngineFactory(new[] { registration }, config.Object, fileSystem.Object);
107+
108+
factory.GetEngineForCurrentThread();
109+
110+
jsEngine.Verify(x => x.Execute("CONTENTS_First.js"));
111+
jsEngine.Verify(x => x.Execute("CONTENTS_Second.js"));
112+
}
84113
}
85114
}

0 commit comments

Comments
 (0)