Skip to content

Commit 3ddc128

Browse files
committed
Unit test for referencing custom React version. References #113
1 parent eecfcac commit 3ddc128

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

src/React.Tests/Core/JavaScriptEngineFactoryTest.cs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using JavaScriptEngineSwitcher.Core;
1313
using Moq;
1414
using NUnit.Framework;
15+
using React.Exceptions;
1516

1617
namespace React.Tests.Core
1718
{
@@ -110,5 +111,50 @@ public void ShouldLoadFilesThatDoNotRequireTransform()
110111
jsEngine.Verify(x => x.Execute("CONTENTS_First.js"));
111112
jsEngine.Verify(x => x.Execute("CONTENTS_Second.js"));
112113
}
114+
115+
[Test]
116+
public void ShouldHandleLoadingExternalReactVersion()
117+
{
118+
var jsEngine = new Mock<IJsEngine>();
119+
jsEngine.Setup(x => x.Evaluate<int>("1 + 1")).Returns(2);
120+
jsEngine.Setup(x => x.CallFunction<bool>("ReactNET_initReact")).Returns(true);
121+
var config = new Mock<IReactSiteConfiguration>();
122+
config.Setup(x => x.ScriptsWithoutTransform).Returns(new List<string>());
123+
config.Setup(x => x.LoadReact).Returns(false);
124+
var fileSystem = new Mock<IFileSystem>();
125+
var registration = new JavaScriptEngineFactory.Registration
126+
{
127+
Factory = () => jsEngine.Object,
128+
Priority = 1
129+
};
130+
var factory = new JavaScriptEngineFactory(new[] { registration }, config.Object, fileSystem.Object);
131+
132+
factory.GetEngineForCurrentThread();
133+
134+
jsEngine.Verify(x => x.CallFunction<bool>("ReactNET_initReact"));
135+
}
136+
137+
[Test]
138+
public void ShouldThrowIfReactVersionNotLoaded()
139+
{
140+
var jsEngine = new Mock<IJsEngine>();
141+
jsEngine.Setup(x => x.Evaluate<int>("1 + 1")).Returns(2);
142+
jsEngine.Setup(x => x.CallFunction<bool>("ReactNET_initReact")).Returns(false);
143+
var config = new Mock<IReactSiteConfiguration>();
144+
config.Setup(x => x.ScriptsWithoutTransform).Returns(new List<string>());
145+
config.Setup(x => x.LoadReact).Returns(false);
146+
var fileSystem = new Mock<IFileSystem>();
147+
var registration = new JavaScriptEngineFactory.Registration
148+
{
149+
Factory = () => jsEngine.Object,
150+
Priority = 1
151+
};
152+
var factory = new JavaScriptEngineFactory(new[] { registration }, config.Object, fileSystem.Object);
153+
154+
Assert.Throws<ReactNotInitialisedException>(() =>
155+
{
156+
factory.GetEngineForCurrentThread();
157+
});
158+
}
113159
}
114160
}

0 commit comments

Comments
 (0)