mon123 mon123 - 1 month ago 10
Java Question

NEW BIE! Jasmine Tests in Spring Maven Project:expect jQuery UI autocomplete is not recognized in the spec

I've setup jasmine testing in my project recently and trying to implement and test the autocomplete functionality in my report.

I'm using the jQuery UI autocomplete function and trying to test if the method call has been made in my spec. But the test is failing, saying that autocomplete function is not recognized.

In the fixture, I've included the javascript file since my autocomplete function call is in the document.ready function and the required jquery, jquery UI js files as well.

I was thinking that this might be a problem with the maven dependencies, so I've included the dependency file as well in addition fixture file.

POM.XML (just the dependency and plulgin)

<dependency>
<groupId>org.webjars</groupId>
<artifactId>jasmine-jquery</artifactId>
<version>2.0.3</version>
<scope>test</scope>
</dependency>

<pluginManagement>
<plugins>
<plugin>
<groupId>com.github.searls</groupId>
<artifactId>jasmine-maven-plugin</artifactId>
<version>2.0</version>
<executions>
<execution>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
<configuration>
<preloadSources>
<source>webjars/jquery.js</source>
<source>webjars/jasmine-jquery.js</source>
<source>http://davidstutz.github.io/bootstrap-multiselect/dist/js/bootstrap-multiselect.js</source>
</preloadSources>
<jsSrcDir>src/main/webapp/resources/js</jsSrcDir>
<jsTestSrcDir>src/test/javascript</jsTestSrcDir>
<webDriverClassName>org.openqa.selenium.phantomjs.PhantomJSDriver</webDriverClassName>
</configuration>
</plugin>
</plugins>
</pluginManagement>


Fixture file:






<title>Fixture File for auto complete</title>
</head>
<body>
<form action="javascript:void(0)" method="get">
<input type="text" id="searchAutoComplete" />
</form>


The script tags in the fixture seem to not come in the post. But I have included both the js file and the jquery-ui.js file in the fixture.

What do you all think about what the problem might be and how to fix it??

Answer

I have modified the pom.xml as shown below:

 <pluginManagement>
  <plugins>
    <plugin>
      <groupId>com.github.searls</groupId>
      <artifactId>jasmine-maven-plugin</artifactId>
      <version>2.0</version>
      <executions>
        <execution>
          <goals>
            <goal>test</goal>
          </goals>
        </execution>
      </executions>
      <configuration>
        <preloadSources>
          <source>webjars/jquery.js</source>
          <source>webjars/jasmine-jquery.js</source>
          <source>${project.basedir}/src/main/webapp/resources/js/lib/jquery-ui.min.js</source>
          <source>http://davidstutz.github.io/bootstrap-multiselect/dist/js/bootstrap-multiselect.js</source>
        </preloadSources>
        <jsSrcDir>src/main/webapp/resources/js</jsSrcDir>
        <jsTestSrcDir>src/test/javascript</jsTestSrcDir>
        <webDriverClassName>org.openqa.selenium.phantomjs.PhantomJSDriver</webDriverClassName>
      </configuration>
    </plugin>
  </plugins>
</pluginManagement>

I have added the jquery-min.js into the project library and included the path in the pom.xml. Thus it works.